paul-pias / Object-Detection-and-Distance-Measurement

Using yolov3 & yolov4 weights objects are being detected from live video frame along with the measurement of the object from the camera without the support of any extra hardware device.
348 stars 118 forks source link

!ssize.empty() in function 'cv::resize' #11

Closed nikoststs closed 4 years ago

nikoststs commented 4 years ago

Hello, Anyone came across the above mentioned problem?? When I choose to load a video , I get this error. However i cant locate the file because the folder it is supposed to be in (opencv-python\opencv\modules\imgproc\src\resize.cpp) does not exist in the specific path ( C:\projects). I have installed opencv-python using pip install. Any ideas?

paul-pias commented 4 years ago

Can you leave a snapshot of your terminal here with the mentioned error?

nikoststs commented 4 years ago

Sure, i am attaching it here PS : the mentioned path C:\projects does not exist. I have also hidden folders to appear and still cant find such path terminal

paul-pias commented 4 years ago

Are you reading the stream using WebcamVideoStream or cv2.VideoCapture? If cv2, have you used ret, frame these 2 variables to unpack values from cap.read().

nikoststs commented 4 years ago

I was giving wrong path to video file, but i fixed it . Now it runs frame by frame, but no info on distance is printed. Also the same error ( !ssize.empty() in function 'cv::resize' ) appears when the video ends, and the code is stuck there.

paul-pias commented 4 years ago

Try installing opencv-contrib-python by running pip install opencv-contrib-python. The info of distance will be printed on the terminal along with as a text on the output frame. You are not seeing it because at your end the code encounters an error in the try-catch block that's why it executing until the error occurs. Whenever the error happens it skips (pass) the rest of the code.

nikoststs commented 4 years ago

The exact same error persists. I have a feeling also that the code never gets into the try block, as ("Current Object"])+ " " +"is"+" at {} ".format(round(distance))+"Inches") is never printed but print("[INFO] elasped time: {:.2f}".format(fps.elapsed())) print("[INFO] approx. FPS: {:.1f}".format(fps.fps())) is printed continuously

paul-pias commented 4 years ago

Is objection detection working on the captured frame? If yes, then the code entered the try-catch block. Anyway which OpenCV version are you using? Try commenting out the cv2.resize method and see what happens. The error is clearly saying that it got an empty frame. If you used cv2.VideoCapture() to capture the feed and ret, frame = cap.read() to read the frames then try printing out the ret variable. It should always print True if it's able to read frames from the camera.

nikoststs commented 4 years ago

Hello @paul-pias . I am using version 4.2.0 of OpenCV. I added the command to print "ret" right after the function frame render declaration. I am getting error that : name 'ret' is not defined PS : I am using cv2.VideoCapture(), im not streaming from camera, but I also tried with live stream from camera and still didnt get info on distances. code

nikoststs commented 4 years ago

Quick Update : I managed to overcome the problem, seems like I should change torch.half to torch.float. The error remains at the last frame of the video , though , where the code also crashes

paul-pias commented 4 years ago

You are printing ret in the outer scope/global scope of the function where the compiler doesn't hold any reference to that variable as ret is used inside a function(inner scope/local scope). The intuition i am getting from your answers is that the error is for basic programming errors. torch.half/ torch.float are the different data types provided by the Pytorch framework. You can use different data types based on your resources to optimize/utilize your code performance. This has nothing to do with the error you mentioned in the issue. As far as i know there is no problem in the code, maybe you are missing few guidelines to run the code. Kindly debug line by line from your end more better understanding if you want.

nikoststs commented 4 years ago

You are right, I need to spend some more time with it. Seems that I got it to run though!

dvickydh17 commented 3 months ago

Hi @nikoststs, how you rectified the issue. Could you provide the steps to solve this issue.