用#include <opencv2/opencv.hpp>怎么解决cvQueryFrame(cam)
时间: 2024-05-14 09:18:14 浏览: 24
如果你使用的是 OpenCV 2.x 版本,可以使用 cv::VideoCapture 类来代替 cvQueryFrame() 函数。示例代码如下:
```
#include <opencv2/opencv.hpp>
int main()
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
std::cerr << "Failed to open camera!" << std::endl;
return -1;
}
cv::Mat frame;
while (true)
{
cap >> frame;
if (frame.empty())
{
std::cerr << "Failed to capture frame!" << std::endl;
break;
}
cv::imshow("Camera", frame);
if (cv::waitKey(30) == 'q')
{
break;
}
}
return 0;
}
```
如果你使用的是 OpenCV 3.x 或更高版本,可以使用 cv::VideoCapture 的 read() 方法代替。示例代码如下:
```
#include <opencv2/opencv.hpp>
int main()
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
std::cerr << "Failed to open camera!" << std::endl;
return -1;
}
cv::Mat frame;
while (true)
{
if (!cap.read(frame))
{
std::cerr << "Failed to capture frame!" << std::endl;
break;
}
cv::imshow("Camera", frame);
if (cv::waitKey(30) == 'q')
{
break;
}
}
return 0;
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)