So recently, I started using OpenCV. I have created a test project to set everything up in Visual Studio 2019. When that project is working, I exported that as a template, and used that to create my actual project. However, I found that the template code is no longer working properly. I have made sure that the include directories are correct, and that the linker is also correct. The code is identical in both projects. The following code works in the original project but not in the new one. I was changing the code in both projects to try to identify the problem, but nothing that I have tried tells me anything helpful.
What happens when I run the code:
In the original project, the waitKey(0) function pauses the program correctly, but in the new project, the program continues to run even if I'm not pushing any buttons.
#include <opencv2/opencv.hpp>
#include <iostream>
int main()
{
cv::VideoCapture cap(1);
cv::Mat frame;
if (!cap.isOpened())
{
std::cout << "Error opening video capture." << std::endl;
return -1;
}
while (1) {
cap >> frame;
if (frame.empty())
break;
cv::imshow("Frame", frame);
char c = (char)cv::waitKey(0);
std::cout << (int)c << std::endl;
if (c == 27)
break;
}
cap.release();
cv::destroyAllWindows();
return 0;
}
Note that in the test project, the program correctly waits for keyboard input, while in the new one, the program just moves on without reading the keyboard.
So, I guess what I want is to see if anyone here have any idea on how to solve this issue.