0

I'm developing a project with visual studio 2010 and opencv. Here is my problem: i acquire a video from webcam, analize it, do some operation on it and then i show the result in another window (Object Tracking). The code is ok, no compiling errors but as soon as i start the program the console windows it closes immediately and i cannot see both the original and the modified video. If i debug the code i can see the webcam works and acquire images but obviously i ned to do this in real time. Any suggestion?

damianodamiano
  • 2,528
  • 2
  • 13
  • 21
  • Possible duplicate of [Microsoft Visual Studio: How to keep the console open without manually reading input?](http://stackoverflow.com/questions/6137009/microsoft-visual-studio-how-to-keep-the-console-open-without-manually-reading-i) – RedX Jun 19 '16 at 18:18
  • Nope, it close even if i click ctr+F5 – damianodamiano Jun 19 '16 at 18:43

2 Answers2

0

Can you give any code? Are you write and compile any video player program like this?

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
//Video Capture cap(path_to_video); // open the video file
if(!cap.isOpened())  // check if we succeeded
return -1;

namedWindow("Video",1);
for(;;)
{
 Mat frame;
 cap >> frame; // get a new frame from camera        
 imshow("Video", frame);
 if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
opencv train
  • 29
  • 2
  • 13
  • #include #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" using namespace cv; using namespace std; int main() { VideoCapture cap(0); while (true) { Mat imgOriginal; Mat imgHSV; bool bSuccess = cap.read(imgOriginal); cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV imshow("Thresholded Image", imgHSV); imshow("Original", imgOriginal); } return 0; } – damianodamiano Jun 19 '16 at 18:47
  • You must display each frame for a 33 mili second( realtime), and then go to next frame. thus add `waitKey(33); ` after `imshow("Original", imgOriginal);` – opencv train Jun 19 '16 at 23:38
0

Try this:

#include <iostream> 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
using namespace cv; 
using namespace std; 
int main() {
VideoCapture cap(0); 
while (true)
{
Mat imgOriginal; 
Mat imgHSV; 
bool bSuccess = cap.read(imgOriginal); 
cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV 
imshow("Thresholded Image", imgHSV); 
imshow("Original", imgOriginal);
waitKey(33);
}
return 0;
} 
opencv train
  • 29
  • 2
  • 13