#include <opencv2/opencv.hpp> #include<iostream> int main(int argc, char const* argv[]) { cv::VideoCapture cap; cap.open("test.mp4"); if (!cap.isOpened()) return 0; int width = cap.get(CV_CAP_PROP_FRAME_WIDTH); //帧宽度 int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //帧高度 int totalFrames = cap.get(CV_CAP_PROP_FRAME_COUNT); //总帧数 int frameRate = cap.get(CV_CAP_PROP_FPS); //帧率 x frames/s std::cout << "视频宽度: " << width << std::endl; std::cout << "视频高度: " << height << std::endl; std::cout << "视频总帧数: " << totalFrames << std::endl; std::cout << "帧率: " << frameRate << std::endl; cv::Mat frame; while (1) { cap >> frame; if (frame.empty()) break; cv::imshow("hello", frame); cv::waitKey(50); } cap.release(); return 0; } 哪里出错了
时间: 2024-04-10 19:34:53 浏览: 150
你的代码中的错误是使用了未定义的标识符`CV_CAP_PROP_FRAME_WIDTH`和`CV_CAP_PROP_FRAME_HEIGHT`。在OpenCV 3及以上的版本中,这些标识符已经被更改为`cv::VideoCapture::CAP_PROP_FRAME_WIDTH`和`cv::VideoCapture::CAP_PROP_FRAME_HEIGHT`。
请将以下行:
```cpp
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH); //帧宽度
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //帧高度
```
更改为:
```cpp
int width = cap.get(cv::VideoCapture::CAP_PROP_FRAME_WIDTH); //帧宽度
int height = cap.get(cv::VideoCapture::CAP_PROP_FRAME_HEIGHT); //帧高度
```
这样就能够正确获取视频帧的宽度和高度了。同样的修改也需要应用到获取总帧数和帧率的部分。
最后,请确保你已经正确包含了OpenCV头文件并链接了OpenCV库。你的代码中已经包含了`#include <opencv2/opencv.hpp>`,但你还需要在编译时链接OpenCV库,例如使用以下命令:
```
g++ your_code.cpp -o your_program `pkg-config --cflags --libs opencv4`
```
这样就应该能够解决问题了。如果还有其他问题,请告诉我。
阅读全文
相关推荐
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.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)
![](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/20241231045053.png)