Я следую руководству, чтобы узнать, как использовать opencv which и практическую библиотеку с tenorflow, особенно для cnn, но у меня есть ошибка
Traceback (most recent call last): File "watermark.py", line 15, in <module> watermark =
image_resize(logo, height=50) File "C:\Users\HP\Desktop\Private\project\cv\utils.py", line 9, in
image_resize (h, w) = image.shape:2 AttributeError: 'NoneType' object has no attribute 'shape' WARN:0
global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674)
SourceReaderCB::~SourceReaderCB terminating async callback
code utils.py
import cv2
import os
def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
if width is None and height is None:
return image
if width is None:
r = height / float(h)
dim = (int(w * r), height)
else:
r = width / float(w)
dim = (width, int(h * r))
resized = cv2.resize(image, dim, interpolation = inter)
return resized
class CFEVideoConf(object):
STD_DIMENSIONS = {
"360p": (480, 360),
"480p": (640, 480),
"720p": (1280, 720),
"1080p": (1920, 1080),
"4k": (3840, 2160),
}
VIDEO_TYPE = {
'avi': cv2.VideoWriter_fourcc(*'XVID'),
'mp4': cv2.VideoWriter_fourcc(*'XVID'),
}
width = 640
height = 480
dims = (640, 480)
capture = None
video_type = None
def __init__(self, capture, filepath, res="480p", *args, **kwargs):
self.capture = capture
self.filepath = filepath
self.width, self.height = self.get_dims(res=res)
self.video_type = self.get_video_type()
def change_res(self, width, height):
self.capture.set(3, width)
self.capture.set(4, height)
def get_dims(self, res='480p'):
width, height = self.STD_DIMENSIONS['480p']
if res in self.STD_DIMENSIONS:
width, height = self.STD_DIMENSIONS[res]
self.change_res(width, height)
self.dims = (width, height)
return width, height
def get_video_type(self):
filename, ext = os.path.splitext(self.filepath)
if ext in self.VIDEO_TYPE:
return self.VIDEO_TYPE[ext]
return self.VIDEO_TYPE['avi']
watermark.py
import numpy as np
import cv2
from utils import CFEVideoConf, image_resize
cap = cv2.VideoCapture(0)
save_path = 'saved-media/watermark.mp4'
frames_per_seconds = 24
config = CFEVideoConf(cap, filepath=save_path, res='720p')
out = cv2.VideoWriter(save_path, config.video_type, frames_per_seconds, config.dims)
img_path = 'images/logo/1.png'
logo = cv2.imread(img_path, -1)
watermark = image_resize(logo, height=50)
cv2.imshow('watermark',watermark)
while(True):
ret, frame = cap.read()
print(frame[50,150])
color=(255,0,0)
start_cord_x=50
start_cord_y=150
stroke=2
w=100
h=200
end_cord_x=start_cord_x+w
end_cord_y=start_cord_y+h
cv2.rectangle(frame,(x,y),(end_cord_x,end_cord_y),color,stroke)
cv2.imshow('frame',frame)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
спасибо за помощь в обнаружении ошибки. Ожидаемый результат: изображение lo go 1.png при включении камеры и загрузке видео показывает как lo go + стандартный результат