arunponnusamy / cvlib

A simple, high level, easy to use, open source Computer Vision library for Python.
http://arunponnusamy.com/cvlib/
MIT License
653 stars 126 forks source link

Could not read frame #2

Closed shrybht closed 5 years ago

shrybht commented 5 years ago

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.

shrybht commented 5 years ago

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.

arunponnusamy commented 5 years ago

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.

shrybht commented 5 years ago

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.

SahithiParsi commented 5 years ago

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

arunponnusamy commented 5 years ago

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 ?

SahithiParsi commented 5 years ago

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

arunponnusamy commented 5 years ago

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--

SahithiParsi commented 5 years ago

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 https://github.com/opencv/opencv/issues/12023

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

arunponnusamy commented 5 years ago

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 ?

SahithiParsi commented 5 years ago

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

shrybht commented 5 years ago

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

arunponnusamy commented 5 years ago

@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.

arunponnusamy commented 5 years ago

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

shrybht commented 5 years ago

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?

arunponnusamy commented 5 years ago

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

shrybht commented 5 years ago

I run my code on command line only.

image

image

arunponnusamy commented 5 years ago

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

shrybht commented 5 years ago

i did already update it to 3.4.3.

arunponnusamy commented 5 years ago

can you post the code you are running ?

shrybht commented 5 years ago

**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.

arunponnusamy commented 5 years ago

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

arunponnusamy commented 5 years ago

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

shrybht commented 5 years ago

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

bogdan245 commented 5 years ago

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.

arunponnusamy commented 5 years ago

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.

mjasonong commented 5 years ago

now if i

It works! Thank you so much.

shrybht commented 5 years ago

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

OmkarVedak commented 5 years ago

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?

Nick-lab commented 5 years ago

same where would this library be ??

arunponnusamy commented 5 years ago

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

snehri commented 4 years ago

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