Unable to get the image from the webcam in a separate file. The output does not work at all any files in the folder where the expected photos. I tried to change the resolution, change cameras, use IplImage instead of Mat If I use IplImage , I get a completely gray image.

 void ShowCam(int CameraToBeOpened) { int i = 0; cv::Mat frame; cv::VideoCapture cap(CameraToBeOpened); cvNamedWindow("Camera", CV_WINDOW_NORMAL); while (true) { if (cap.read(frame)) imshow("Camera", frame); char c = cvWaitKey(50); if (c == 27) break; if (c == 32) { char filename[200]; sprintf_s(filename, "\Test pictures\test_%d.jpg", i); i++; cv::imwrite(filename, frame); std::cout << "Image has been captured" << std::endl; } } cvDestroyAllWindows(); 
  • Do you even get into a branch with cv::imwrite before checking the result in the folder? - αλεχολυτ
  • Yes, of course, there are special std::cout << "Image has been captured" << std::endl; and it works out every time - zhuk
  • and the return code is there? - αλεχολυτ

1 answer 1

Problem solved. It was enough to change the path to the saved files using the pattern sprintf_s(filename, "test_%d.jpg", i)

Question on stackoverflow