解决 CAP_IMAGES: can‘t find starting number (in the name of file)
解决 CAP_IMAGES: can't find starting number (in the name of file)
- 1. 解决方法
- 2.报错代码
- 3.报错Log
- 4.错误分析
- 5.opencv源码分析
1. 解决方法
1.确认输出文件类型与fourcc需匹配。具体可参考官网http://www.fourcc.org/codecs.php。
简单点就用 .avi 配 VideoWriter::fourcc(‘M’, ‘J’, ‘P’, ‘G’)。
网上搜到一个贴说什么fourcc是旧版本用的,现在不用了,这种说发的是错的哈。对于Opencv4.3.x,依然采用fourcc。当编译不过时应把类名加上VideoWriter::fourcc(‘X’, ‘X’, ‘X’, ‘X’)。
2.第1步无误但还是报错的话:
Linux平台:重新安装ffmpeg,然后重新编译opencv并安装。opencv编译时 cmake需加上参数-DWITH_FFMPEG=ON。
Window平台:可将输出文件类型改为.mp4。此方法为偷懒法,无需安装ffmpeg。
以下详细解释偷懒法能生效的原因。
2.报错代码
#define VIDEO_OUTPUT_PATH "D:\\test_project\\output.avi" //我原来代码输出文件类型为.aviint main()
{Mat frame;frame = imread("xxx.jpg");// Mat数据保存为视频VideoWriter vWriter(VIDEO_OUTPUT_PATH, CAP_OPENCV_MJPEG, 30, Size(frame.cols, frame.rows));//上面参数使用CAP_OPENCV_MJPEG是错误的哈,VideoWriter::fourcc('M', 'J', 'P', 'G')才是正确的参数int frameNum = 90; //定义我要存多少帧while (frameNum) {vWriter << dst;frameNum--;}return 0;
}
3.报错Log
[ERROR:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\cap.cpp (563) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:OpenCV(4.5.1) C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): D:\\test_project\\output.avi in function 'cv::icvExtractPattern'
4.错误分析
上面两句是运行时的报错信息。
第一句就是VideoWriter::open运行时收到异常。
第二句是具体的异常内容:
OpenCV(4.5.1) C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can’t find starting number (in the name of file): D:\test_project\output.avi in function ‘cv::icvExtractPattern’
我们可以从报错log中得出以下信息:
- 错误log由文件cap_images.cpp 第253行打印
- 貌似是文件名有点问题
- 具体是cv::icvExtractPattern函数中打印的
那么接下来就看下opencv源码,查一查我的文件名到底有什么问题
5.opencv源码分析
//在opencv\modules\videoio\src\cap.cpp 中找到 icvExtractPattern 函数
std::string icvExtractPattern(const std::string& filename, unsigned *offset)
{size_t len = filename.size(); //记录文件名长度。。。。。。//一堆操作,不用关心pos = filename.rfind('/'); //找到文件名中最后一个"/"的位置
#ifdef _WIN32if (pos == std::string::npos)pos = filename.rfind('\\'); //对于window 系统,找到文件名中最后一个"\\"的位置
#endifif (pos != std::string::npos)pos++;elsepos = 0;while (pos < len && !isdigit(filename[pos])) pos++; //文件名错误的关键点if (pos == len) //如果位置等于文件名长度,则抛出异常{CV_Error_(Error::StsBadArg, ("CAP_IMAGES: can't find starting number (in the name of file): %s", filename.c_str()));}。。。。。。//一堆操作,不用关心
}
以上代码实现的应该是从输出文件名找到需要输出的文件类型。
因为关键点 while (pos < len && !isdigit(filename[pos])) pos++; 这里实现的是如果文件名中 pos所指的字符不是数子,那么pos就++,指向下一个字符。看起来因该就是想要找到带数子的文件名。
因此灵机一动,将输出文件的文件类型设置为mp4,然后问题就解决了。
#define VIDEO_OUTPUT_PATH “D:\test_project\output.avi”
改为:
#define VIDEO_OUTPUT_PATH “D:\test_project\output.mp4”
如有帮助,不妨点赞关注以支持。
解决 CAP_IMAGES: can‘t find starting number (in the name of file)相关推荐
- CV报错:CAP_IMAGES: can‘t find starting number (in the name of file): x in function ‘icvExtractPattern‘
在linux arm下报错: OpenCV(4.5.4-dev) /home/yg/share/prj/opencv/modules/videoio/src/cap_images.cpp:253: e ...
- openCV4.2.0 error: (-5:Bad argument) CAP_IMAGES: can’t find starting number (in the name of file)
OpenCV(4.2.0-dev) ~/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAG ...
- 成功解决An error ocurred while starting the kernel
成功解决An error ocurred while starting the kernel 目录 解决问题 解决思路 解决方法 解决问题 An error ocurred while startin ...
- 解决ubuntu18.04卡在“starting Gnome Display Manager“
解决ubuntu18.04卡在"starting Gnome Display Manager" 问题场景: 在ubuntu安装NVIDIA驱动后,重启电脑后卡在"star ...
- 解决IntelliJ IDEA报错Failed to read candidate component class: file [ ]; nested exception is org.
解决IntelliJ IDEA报错Failed to read candidate component class: file [ ]; nested exception is org.springf ...
- 解决微信返回码为40113,错误信息errmsg:unsupported file type
解决微信返回码为40113,错误信息"errmsg":"unsupported file type" // PHP代码 $file_name = md5(mic ...
- 报错解决:SyntaxError: Non-UTF-8 code starting with ‘\xe7‘
今天抓取数据时使用re对数据进行提取时遇到的问题:syntaxError: Non-UTF-8 code starting with '\xe7',意思是有的中文字符无法转成utf-8的形式,如图所示 ...
- 解决java.lang.UnsupportedClassVersionError: Bad version number in .class file问题
在启动tomcat服务器时, 报如下的错误: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading ...
- php deprecated是什么意思,解决:PHP Deprecated: Comments starting with '#' are deprecated in ……...
错误信息:PHP Deprecated: Comments starting with '#' are deprecated in /usr/local/php/etc/php.ini on lin ...
- 解决:SyntaxError: Non-UTF-8 code starting with '\xe6' in file
pycharm加注释报错SyntaxError: Non-UTF-8 code starting with '\xe6' in file 处理 代码最上面加上编码格式 #coding:utf-8
最新文章
- 在PyPI上发布自己的python包
- ping 工具开发日记(1)
- html5如何绘制饼图,如何在HTML5中创建“饼图”?
- oracle 更新数据更新不进去_关于微软及Oracle安全更新汇总的通知
- web.xml filter 不包含_Elasticsearch 之 Filter 与 Query 有啥不同?
- Linux之pwd命令
- [CATARC_2017] 第三周 残四周
- 23种经典设计模式UML类图汇总
- java smali_如何把java代码转换成smali代码
- 安装nodejs时:The error code is 2503.
- 海康威视摄像头 rtsp 地址格式
- 砸蛋程序php,砸金蛋:jQuery+PHP实现的砸金蛋中奖程序
- cursor android,Android Cursor用法
- idea中javaweb的jsp页面图片加载不出来的解决办法
- 关于判别分析的学习-距离判别法
- msp430流水灯c语言程序,MSP430单片机流水灯程序
- Tiny4412 在linux下的dnw使用
- 2022登高架设理论题库及答案
- 用7000字长文带你分析深圳二手房市场现况!
- 几个常见的js插件安装配置
热门文章
- 使用pyppeteer或者selenium时,chrome窗口最大化
- 电驴无法增加服务器怎么办,电驴连接不上服务器怎么办?
- 2018校招-挂面-H3C-技术支持工程师
- android studio sdk samples,qcloud-sdk-android-samples
- 520送男朋友什么礼物最好、送男友礼物清单
- 网盘上传文件服务器失败原因,百度网盘上传文件一直失败是什么情况?具体解决方法...
- 同频共振数据时代,AntDB数据库与永洪科技完成产品互认证
- mysql调整specified key_MySQL错误“Specified key was too long; max key length is 1000 bytes”的解决办法...
- iOS开发:唯一标志符
- 算法篇-----粒子群算法