Strange behavior when displaying images using OpenCV and Qt

I collect images from Cam using the OpenCV C API and send them using TCP sockets.

The server starts C ++ (QT) and receives the frame.

The process is working fine and I see images on the server.

The strange problem is that when I close both programs and restart the client and server, I can see the previous frame that I saw in the previous test.

If I close both programs again and repeat them, I see a new frame, not a second one, and the process continues.

To make this clearer:

capture1, close, cap1, close, cap3, close, cap3, close, cap5 ...... etc

I had never seen anything like it before!

+4
source share
3 answers

I had the same problem before.

the frame size to a large extent and you read from the buffer randomly (just guessing), you need to make a timer or confirmation between the camera and OpenCV.

Just try to control how the camera captures frames.

+2
source

I don’t know much about TCP / IP programming or a lot about the client / server ... but all I can offer is to initialize the images, as a rule, in the constructors of the camera / client / server class,

Mat Frame = Mat::zeros(rows,cols,CV_8UC3); 

so every time the client / server is initialized or before you are ready to share images ... the initial image is a blank image ...

you must initialize with cvCreatImage() .. so you can do the following ...

 IplImage *m = cvCreateImage(cvSize(200,200),8,3);// say its 200 x 200 cvZero(m); cvShowImage("BLANK",m); cvvWaitKey(); 

it shows a black image with every pixel as zero ...

+1
source

Of course, this problem comes from the camera. It seems that the camera receives any confirmation after capturing the frame. One thing you can try is go to the line of code that sends the image and saves the image to disk to check if cap1 is sent twice.

+1
source

All Articles