简体   繁体   English

在OpenCV中使用cv :: imwrite运行时错误

[英]Run time error using cv::imwrite in OpenCV

I am using OpenCV 2.3.1. 我正在使用OpenCV 2.3.1。 My language is C++. 我的语言是C ++。

cv::imwrite works fine if I hard code the name of the output file like this. 如果我这样硬编码输出文件的名称,则cv :: imwrite可以正常工作。

cv::imwrite("/home/peter/BlendedInterpolatedPlane.jpg", srcnorm);

However, I get a run time error when I try to pass the output file name as a string like this. 但是,当我尝试将输出文件名作为这样的字符串传递时,出现运行时错误。

cv::imwrite(outputFileName.c_str(), srcnorm);

or like this 或像这样

cv::imwrite(outputFileName, srcnorm);

although there is no compiler error. 尽管没有编译器错误。

outputFileName is declared as std::string and contains the output file name. outputFileName声明为std :: string,并包含输出文件名。

The stack trace is as follows. 堆栈跟踪如下。

org.netbeans.modules.viewmodel.TreeModelNode@1999add[Name=, displayName=__kernel_vsyscall()]    
org.netbeans.modules.viewmodel.TreeModelNode@186304c[Name=, displayName=raise()]    
org.netbeans.modules.viewmodel.TreeModelNode@cce801[Name=, displayName=abort()] 
org.netbeans.modules.viewmodel.TreeModelNode@93b1a8[Name=, displayName=__gnu_cxx::__verbose_terminate_handler()()]  
org.netbeans.modules.viewmodel.TreeModelNode@749412[Name=, displayName=Address: [@0x00554fa5]]  
org.netbeans.modules.viewmodel.TreeModelNode@1a52b00[Name=, displayName=std::terminate()()] 
org.netbeans.modules.viewmodel.TreeModelNode@aa277d[Name=, displayName=__cxa_throw()]   
org.netbeans.modules.viewmodel.TreeModelNode@106904c[Name=, displayName=cv::error(cv::Exception const&)()]  
org.netbeans.modules.viewmodel.TreeModelNode@1eb6f21[Name=, displayName=cv::imwrite_(std::basic_string<char, std::char_traits<char>,   std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&, bool)()]   
org.netbeans.modules.viewmodel.TreeModelNode@1ccf1f3[Name=, displayName=cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)()]    
org.netbeans.modules.viewmodel.TreeModelNode@20a41d[Name=, displayName=main(argc=9,argv=0xbffff564) at main.cpp:259]

Any assistance would be greatly appreciated, 任何帮助将不胜感激,
Peter 彼得

I found the problem. 我发现了问题。 The output file name had an invalid suffix. 输出文件名的后缀无效。 Once I fixed that problem, it worked with 一旦我解决了这个问题,它就可以解决

cv::imwrite(outputFileName, srcnorm);

where outputFileName is of type std::string. 其中outputFileName的类型为std :: string。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM