arunponnusamy / cvlib

A simple, high level, easy to use, open source Computer Vision library for Python.

Home Page:http://arunponnusamy.com/cvlib/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not read frame

shrybht opened this issue · comments

Hi @arunponnusamy

I am trying to run object_detection_webcam.py.

[ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772 [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772 [ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772 Could not read frame

It is unable to read the frame. Could you help me understand what went wrong?

Thanks.

Also could you tell me if there are any specific commands I need to enter while running Object_detection.py?

Because I'm getting the error:
Traceback (most recent call last): File "object_detection.py", line 8, in <module> image = cv2.imread(sys.argv[1]) IndexError: list index out of range

Thank you.

Hello @shrybht ,

object_detection.py accepts an input image to apply object detection. Usage is mentioned at the top of the file as comment.

# object detection example
# usage: python object_detection.py <input_image> 

Regarding object_detection_webcam.py, I guess the issue is in accessing webcam at platform level. Are you working with Windows ?

Have a look at this issue on OpenCV forum.

Try replacing cv2.VideoCapture(0) with cv2.VideoCapture(cv2.CAP_DSHOW). Let me know if it works.

Hi,
For object_detection.py, I was trying to see if its possible images can be read from a folder one after the other. Anyway, thanks for the clarification.

Yes, I'm working on Windows. The link you provided was really helpful. I appreciate you taking the effort and sending me the link.

My output is:

image

I am going wrong somewhere?

Thank you.

Same with me output is an empty array. I am able to read the image but cv.detect_common_objects function is not giving any output.
emptyarray

Hello @SahithiParsi , May I know the output image you are getting ? It is showing the webcam feed correctly ? Are you getting any warning or errors while executing the script ?

Hello @SahithiParsi , May I know the output image you are getting ? It is showing the webcam feed correctly ? Are you getting any warning or errors while executing the script ?

FYI - i am using windows. Anything in particular with machine?
displayscreen

I think you guys are working with Jupyter notebook. Displaying images / webcam feed is little different on notebooks. Have a look at the below links to get some insights.
https://medium.com/@neotheicebird/webcam-based-image-processing-in-ipython-notebooks-47c75a022514
https://colab.research.google.com/drive/1N850w27QQHmJNMrZqtzsUpKWx33H0X--

I think issue is not jupyter notebook. I tried object detection for image in spyder. it is also displaying an empty arrray.
I am using Opencv3.4.3, Python 3.6,

objectdetection

Reg - version upgrades
@shrybht if you are using open cv 3.4.1 object detection modules were not updated as mentioned in
opencv/opencv#12023

but even after upgrading the version. i cant see the output

May be it didn't detect the phone in the image. Can you try with this image https://github.com/pjreddie/darknet/blob/master/data/person.jpg please ?

Firstly,
it dint work
objectdetection_output
But
Surprisingly dint face any issue with yolo_opencv
yolo_opencv_op

OpenCV I'm using 3.4.2, Python 3.6 and I'm using PyCharm for object detection.

@SahithiParsi can you use this script from terminal with an input image ?
https://github.com/arunponnusamy/cvlib/blob/master/examples/object_detection.py
python object_detection.py <path to input image>
If the image is in current directory
python object_detection.py person.jpg

I am suspicious about the os.chdir line in your script.

I am closing this issue. Feel free to reopen if the issue persists.

Hi Arun,

I re-did everything from the scratch and I am facing similar error as to what has been discussed above. The output is an empty array, i.e the image on webcam is being displayed but there is no bounding box around the image.

A quick question, I have earlier tried https://github.com/arunponnusamy/object-detection-opencv, using YOLO: object detection and works perfect. May I know how to make changes to this code so I can use real-time data to run the code?

Can you run this code from command line ?
https://github.com/arunponnusamy/cvlib/blob/master/examples/object_detection_webcam.py
python object_detection_webcam.py

I run my code on command line only.

image

image

Can you try updating OpenCV to the latest version ?
pip install --upgrade opencv-python

i did already update it to 3.4.3.

can you post the code you are running ?

**import cvlib as cv
from cvlib.object_detection import draw_bbox
import cv2
import matplotlib.pyplot as plt

open webcam

#webcam = cv2.VideoCapture(0)
print("v=%s" % cv2.version)
webcam = cv2.VideoCapture(0)
h = webcam.get( cv2.CAP_PROP_FRAME_HEIGHT )
w = webcam.get( cv2.CAP_PROP_FRAME_WIDTH )
print("Camera H=%d, W=%d" % (h,w) )

If I remove these two lines it works but is stuck at 640x480

webcam.set( cv2.CAP_PROP_FRAME_HEIGHT, 480 )
webcam.set( cv2.CAP_PROP_FRAME_WIDTH, 640 )
h = webcam.get( cv2.CAP_PROP_FRAME_HEIGHT )
w = webcam.get( cv2.CAP_PROP_FRAME_WIDTH )
print("Camera H=%d, W=%d" % (h,w) )

if not webcam.isOpened():
print("Could not open webcam")
exit()

loop through frames

while webcam.isOpened():

# read frame from webcam 
status, frame = webcam.read()

if not status:
    print("Could not read frame")
    exit()

# apply object detection
bbox, label, conf = cv.detect_common_objects(frame)

print(bbox, label, conf)

# draw bounding box over detected objects
out = draw_bbox(frame, bbox, label, conf)

# display output
cv2.imshow("Real-time object detection", frame)

# press "Q" to stop
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

webcam.release()
cv2.destroyAllWindows()**

I did also try the below code by just trying an input:

**fig = cv2.imread("C:/Users/shry/Projects/coco/coco_val/val2017/000000000285.jpg")
bbox, label, conf = cv.detect_common_objects(fig)

print(bbox, label, conf)
out = draw_bbox(fig, bbox, label, conf)
cv2.imshow("Image", fig)
cv2.waitKey(0)
cv2.destroyAllWindows()**

But, this too is just giving the image output without any bounding boxes.

can you try changing frame with out in the cv2.imshow() call ?
cv2.imshow("Real-time object detection", out)

Try deleting the .cvlib folder in your home directory and run the script again. There might be issue in the weights file downloaded.

I did change the frame with out and also deleted the .cvlib but of no use. I'm still getting the same output.

I have a similar problem. When i run the code, the output that i get it's just the image from my camera, the cvlib is not able to read any frame i think, and the camera reads the frames very slowly.

Hello @shrybht and @bogdan245 , I have fixed an issue in the config file. I think now it should work as expected. Delete .cvlib folder in the home directory(~) and try now. Let me know if you still face issue.

now if i

It works! Thank you so much.

Thank you for the update Arun. It's working.

Hello @shrybht and @bogdan245 , I have fixed an issue in the config file. I think now it should work as expected. Delete .cvlib folder in the home directory(~) and try now. Let me know if you still face issue.

Where can I find .cvlib folder in windows?

same where would this library be ??

It will be in the home directory.
cd ~
Command will take you to the home directory.

Hi @arunponnusamy
self.cap = cv2.VideoCapture(cv2.CAP_DSHOW)
with code [ WARN:0] videoio(MSMF): OnReadSample() is called with error status: -1072875772 [ WARN:0] videoio(MSMF): async ReadSample() call is failed with error status: -1072875772
[ WARN:1] videoio(MSMF): can't grab frame. Error: -1072875772 Could not read frame

Succesfull. But very slow and sometimes it closes. No error.
for .cvlib I couldn't find the file path :/
Thanks