imwrite不保存帧



我试图将框架及其路径保存到数据库和文件存储中,但不知何故框架没有保存在我提供的路径中,打印路径似乎很好,但我只得到我正在创建的目录,而不是其中的图片,需要帮助,提前感谢

def get_frames(cap=0):
frames = cv2.VideoCapture(cap)
now_utc = dt.now(timezone('UTC'))
now_local = now_utc.astimezone(get_localzone())

data = {}

success,image = frames.read()
scaling_factor = 0.5
count = 0
while True:

if not success:
break
# save frame as JPEG file      
success,image = frames.read()
image = cv2.flip(image,1)
#adding guassian blur
image = cv2.resize(image, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA)

# lower = [18, 50, 50]
# upper = [35, 255, 255]
# lower = np.array(lower, dtype="uint8")
# upper = np.array(upper, dtype="uint8")
# mask = cv2.inRange(hsv, lower, upper)

# output = cv2.bitwise_and(image, hsv, mask=mask)

# no_red = cv2.countNonZero(mask)
# if int(no_red) > 15000:
#     Fire_Reported = Fire_Reported + 1
count += 1

cv2.imshow("frame", image)

ret,buffer = cv2.imencode('.jpeg',image)


dtString =  dt.now().strftime('%d-%m-%Y')
BASE_DIR = Path(__file__).resolve().parent.parent
path = os.path.join(BASE_DIR,f'camera_frames_{dtString}') 
if not os.path.exists(path):
os.makedirs(path)

imgName = os.path.join(path ,dt.now().strftime('%m/%d/%Y %I:%M:%S')+'.jpeg')
saved_frame = cv2.imwrite(imgName, image) 
if count <= 20:
camera_ins = get_or_create(db.session,Cameras,alias_name='test_cam',camera_no=1)
frame_ins = CameraFrames(date_time=now_local.strftime(format),camera_image=imgName)
camera_ins.frames.append(frame_ins)
db.session.add(camera_ins)
db.session.add(frame_ins)
db.session.commit()
frame = buffer.tobytes()


yield(b'--framern'
b'Content-Type: image/jpegrnrn' + frame + b'rn')

if cv2.waitKey(10) == 27:
break

正如@Micka最初指出的那样,我在帧中使用了错误的命名约定,这导致了imwrite的失败,以及不允许出现沉默的错误,例如:,我只是删除了那些

相关内容

  • 没有找到相关文章

最新更新