- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am trying to convert the frame into grayscale by using the open_images_capture function. There has an error when the frame is converting into grayscale. The figure below shows the error message.
Is there any solution to solve it?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Lc00,
Based on the limited information shared from your code snippet, I was not able to fully comprehend how your demo is running. However, you did mention that it works if you use cv2.VideoCapture instead of the open_images_capture function.
For your information, the open_images_capture function is somewhat similar to the workaround code I shared previously. The difference is that the open_images_capture function does not return the status value which is needed to check whether the frame is available to be loaded before the cvtColor function.
Here is the code snippet from open_images_capture as an example:
I would suggest you try these possible methods:
- Call your cvtColor function after the if not status inside of the open_images_capture function.
- Return the status value to your function and use the previous workaround code.
Regards,
Hairul
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Lc00,
Thank you for reaching out to us.
This error occurs when the image is not properly loaded in OpenCV. Please ensure the following:
- Verify the image exists in the path that you have given.
- Verify that your webcam is not being used on another task.
Asides from that, when using cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) function, OpenCV is unable to read the final frame of the video as the object passed to cvtColor function is empty. You can refer to this GitHub discussion (This is an external link and is not maintained by Intel).
Here is an example workaround code that you can try:
source = cv2.VideoCapture('video.mp4')
while True:
ret, img = source.read()
if ret == False:
break
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("Live", gray)
key = cv2.waitKey(1)
if key == ord("q"):
break
cv2.destroyAllWindows()
source.release()
Regards,
Hairul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the information.
I have already tried the code you have given is working but when I replace the cv2.VideoCapture with open_images_capture function which existing in omz/demos/common/python there have errors like the picture shown above. Below is my code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Lc00,
Based on the limited information shared from your code snippet, I was not able to fully comprehend how your demo is running. However, you did mention that it works if you use cv2.VideoCapture instead of the open_images_capture function.
For your information, the open_images_capture function is somewhat similar to the workaround code I shared previously. The difference is that the open_images_capture function does not return the status value which is needed to check whether the frame is available to be loaded before the cvtColor function.
Here is the code snippet from open_images_capture as an example:
I would suggest you try these possible methods:
- Call your cvtColor function after the if not status inside of the open_images_capture function.
- Return the status value to your function and use the previous workaround code.
Regards,
Hairul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. The problem already sloved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Lc00,
Glad to know that your issue has been resolved.
This thread will no longer be monitored since this issue has been resolved. If you need any additional information from Intel, please submit a new question.
Regards,
Hairul
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page