While-loop in opencv causing error

While trying to track objects in real time using opencv, I came across a demo of "find object" for pyopencv . This script does what I want, except that it compares one static image with another, while I am trying to compare a static image with the current frame captured from a webcam. To this end, I replaced this line

scene_filename = "box_in_scene.png" 

with this

 capture = cv.VideoCapture(0) frame = Mat() capture >> frame imwrite("box_in_scene.png",frame) 

This works as it should, but when I try to add a simple loop to get it to do this continuously, it goes through one loop and then stops. When I exit the script, I get the following error:

  OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupport ed array type) in cvGetMat, file M:\programming\packages\opencv\workspace\2.1\Op enCV-2.1.0\src\cxcore\cxarray.cpp, line 2476 Traceback (most recent call last): File "find_obj.py", line 114, in <module> imageDescriptors = surf(image, mask, imageKeypoints) RuntimeError: M:\programming\packages\opencv\workspace\2.1\OpenCV-2.1.0\src\cxco re\cxarray.cpp:2476: error: (-206) Unrecognized or unsupported array type in fun ction cvGetMat 

Does anyone know what might cause this?

The cycle that I use

 myloop = 1 while myloop == 1 : 

This link is the whole code.

+4
source share
1 answer

A few things come to mind right after learning your code. First, you declare a new Mat () and two new namedWindow objects EVERY cycle time. Although this may cause a memory error after several thousand cycles (depending on your computer and OS), this is most likely not your main problem. This, however, is a terrible way to do things and have a bad habit of joining.

My second problem with your code is that you scan the image from the camcorder, save it to a file, and then load the file into memory again so you can use the image! I understand that I want to save a copy of the image in the memory from the camera, but you already have the memory, so why reboot it? If you are in windows, this may be the source of your bad matrix, as it is known that VC ++ 10 libs have some problems with imwrite and imread. [EDIT] I know that you are using python, but your program reports an error from the .cpp file, which means that the python import is actually linked to C ++ libs somewhere [/ EDIT]

Try removing the imwrite and imread calls in your loop and use the image directly from the camera. If after that your code works, you will find out where your problems are. Let us know how this happens.

0
source

Source: https://habr.com/ru/post/1390103/


All Articles