最近在学《学习OpenCV3(中文版)》,第二章【写入AVI文件】的示例2-11运行结果出现错误,现在把出现的问题及办法和大家分享、交流一下。


问题1:

”CV_FOURCC”未定义标识符。

解决办法:把【CV_FOURCC('M', 'J','P','G')】改为【CAP_OPENCV_MJPEG

注:别忘记在全局加【using namespace cv;】,否则还是会报错!


问题2:

如果最后生成的视频是 .AVI 格式的,视频打不开。

解决办法:把生成的视频格式改成 .mp4

虽然会出现:【OpenCV: FFMPEG: tag 0x00000898/'???' is not found (format 'mp4 / MP4 (MPEG-4 Part 14)')'】,但是视频能正常播放。

对数极坐标形式视频(截图)

【测试代码】:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;  //不要忘记这句代码!!!

int main(int argc, char** argv)
{
	cv::namedWindow("2-11", cv::WINDOW_AUTOSIZE);
	cv::namedWindow("Log_Polar", cv::WINDOW_AUTOSIZE);
	cv::VideoCapture capture("C:\\Users\\Administrator\\Desktop\\task.AVI");
	
	double fps = capture.get(cv::CAP_PROP_FPS);
	cv::Size size(
		(int)capture.get(cv::CAP_PROP_FRAME_WIDTH),
		(int)capture.get(cv::CAP_PROP_FRAME_HEIGHT)
	);
	cv::VideoWriter writer;
	writer.open("C:\\Users\\Administrator\\Desktop\\demo.mp4", CAP_OPENCV_MJPEG, fps, size);
	cv::Mat logpolar_frame, bgr_frame;
	for (;;)
	{
		capture >> bgr_frame;
		if (bgr_frame.empty()) break;
		cv::imshow("2-11", bgr_frame);
		cv::logPolar(bgr_frame, logpolar_frame, cv::Point2f(bgr_frame.cols / 2, bgr_frame.rows / 2), 40, cv::WARP_FILL_OUTLIERS);
		cv::imshow("Log_Polar", logpolar_frame);
		writer << logpolar_frame;
		char c = cv::waitKey(10);
		if (c == 27)break;

	}
	capture.release();
}

特别鸣谢:

If you look down, that's where you'll go.
如果你往下看,那你也只会往下摔。

GitHub 加速计划 / opencv31 / opencv
232
21
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:2 个月前 )
f704001e Test: Add regression test for LINE_4 vs LINE_8 connectivity #28120 Add test to verify correct behavior of LINE_4 (4-connected) and LINE_8 (8-connected) line drawing. This test ensures: - LINE_4 produces staircase pattern (more pixels) for diagonal lines - LINE_8 produces diagonal steps (fewer pixels) - LINE_4 pixels have only horizontal/vertical neighbors (no diagonal-only) Regression test for issue #26413 where LINE_4 and LINE_8 behaviors were swapped. 17 小时前
2bf4f5c1 Fix ORB inconsistency for masks with values 255 and 1. #26366 ### Pull Request Readiness Checklist The PR fixes : [25974](https://github.com/opencv/opencv/issues/25974) See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 18 小时前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐