Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

How to use cudacodec + blobFromImage

$
0
0
The problem is that i can't transfer my frame from cv2.cudastream directly to cv2.blobFromImage. Here is a part of my implementation (I skipped many parts of code, 'cause it is not necessary) ... net = cv2.dnn.readNetFromDarknet(configPath, weightsPath) ln = net.getLayerNames() ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()] vs2 = cv2.cudacodec.createVideoReader(stream_name) while True: (grabbed, frame1) = vs2.nextFrame() frame = cv2.cuda.resize(frame1, (416, 416)) net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA) blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False) ... Separately cudacodec and blobFromImage (with VideoCapture) works fine, also if i do frame2 = frame_res.download() frame = frame2[:, :, :3] blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False) It works still fine. However, if i load frame without `.download` and directly to blobFromImage an error occurs Traceback (most recent call last): File "yolo_recog.py", line 559, in main() File "yolo_recog.py", line 552, in main args.one_video File "yolo_recog.py", line 455, in testsys dir_to_images) File "yolo_recog.py", line 181, in video_processing blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False) TypeError: Expected Ptr for argument 'image' After that i change blobFromImage to blobFromImages and get another error Traceback (most recent call last): File "yolo_recog.py", line 559, in main() File "yolo_recog.py", line 552, in main args.one_video File "yolo_recog.py", line 455, in testsys dir_to_images) File "yolo_recog.py", line 181, in video_processing blob = cv2.dnn.blobFromImages(frame, 1 / 255.0, (416, 416), swapRB=True, crop=False) SystemError: returned NULL without setting an error How can i transfer a frame from cudacodec to blobfromimage without downloading it to CPU?

Viewing all articles
Browse latest Browse all 2088

Trending Articles