[英]Failed to use imwrite() in Qt Creator in Debug mode
I used imwrite()
function in Qt Creator. 我在Qt Creator中使用了
imwrite()
函数。 I failed to run the code in Debug mode,while successfully in Release mode. 我无法在“调试”模式下运行代码,而在“发布”模式下成功运行。 I wrote a test program.The followings is what I have done: First to use
OpenCV
, I added the following code in .pro: 我写了一个测试程序。下面是我所做的:首先使用
OpenCV
,我在.pro中添加了以下代码:
INCLUDEPATH+=D:\Work_Software\OpenCV3.1\opencv\build\include
LIBS+=D:\Work_Software\OpenCV3.1\opencv\build\x64\vc12\lib\*.lib
Then I added a Push Button. 然后我添加了一个按钮。 The slot function is:
插槽功能是:
void MainWindow::on_pushButton_clicked()
{
Mat img;
img=imread("F:\\My_Desktop\\foot1.jpg",0);
imwrite("F:\\My_Desktop\\result.jpg",img);
namedWindow("test");
imshow("test",img);
waitKey(0);
}
Finally, in Release mode, I can successfully read and write the image. 最后,在发布模式下,我可以成功读取和写入映像。 However, failed to write in Debug mode.
但是,无法在“调试”模式下写入。 The error information is:
错误信息是:
UPDATE UPDATE
imread
works in debug mode, for example, I change the slot function into: imread
在调试模式下工作,例如,将slot函数更改为:
void MainWindow::on_pushButton_clicked()
{
Mat img;
img=imread("F:\\My_Desktop\\foot1.jpg",0);
namedWindow("test");
imshow("test",img);
waitKey(0);
imwrite("F:\\My_Desktop\\result.jpg",img);
}
I can successfully load and imshow
the image in Debug mode, but when I closed the windows, the same error happened. 我可以在“调试”模式下成功加载并
imshow
图像,但是当我关闭窗口时,发生了相同的错误。
The content of lib folder: lib文件夹的内容:
I have just seen a problem like mine similar problem , but it could not fix mine. 我刚刚看到了一个类似我的问题的问题 ,但是它无法解决我的问题。
It happens because you included all library using *.lib command. 这是因为您使用* .lib命令包含了所有库。 In debug mode if you links with release libraries it fails.
在调试模式下,如果您链接到发行版库,它将失败。 It works in release mode cause it links with release libs as it comes first due to string sort.
它在发布模式下工作,因为它由于字符串排序而与发布库链接在一起。 See the image
看图片
Here 2411 d .lib stands for debug library and 2411.lib stands for release library. 这里2411 d .lib代表调试库,2411.lib代表发布库。 I faced this issue and fixed separate linking in debug & release mode.
我遇到了这个问题,并在调试和发布模式下修复了单独的链接。 You can either make 2 folders of debug and release libraries or you can mention the library names instead of *.lib.
您可以制作2个调试和发布库文件夹,也可以提及库名而不是* .lib。
[change the version for you] [为您更改版本]
Debug link: LIBS+=D:\\Work_Software\\OpenCV2.411\\opencv\\build\\x64\\vc12\\lib\\*d.lib 调试链接:LIBS + = D:\\ Work_Software \\ OpenCV2.411 \\ opencv \\ build \\ x64 \\ vc12 \\ lib \\ * d.lib
Release link: LIBS+=D:\\Work_Software\\OpenCV2.411\\opencv\\build\\x64\\vc12\\lib\\*2411.lib 发布链接:LIBS + = D:\\ Work_Software \\ OpenCV2.411 \\ opencv \\ build \\ x64 \\ vc12 \\ lib \\ * 2411.lib
OR 要么
To separate folder See the images: 分离文件夹请参见图像:
Folder stucture: 文件夹结构:
Debug Library folder: 调试库文件夹:
Release Library folder: 发布库文件夹:
UPDATE UPDATE
If opencv is not built with qt properly please follow link 如果opencv不是用qt正确构建的,请点击链接
OpenCV dll and lib files are differ in terms of CPU architecture (32-64 bit) and Debug-Release mode. OpenCV dll和lib文件在CPU体系结构(32-64位)和调试释放模式方面有所不同。 if you switch to Debug mode you must use dll and lib files for Debug mode (depends on CPU architecture).
如果切换到调试模式,则必须将dll和lib文件用于调试模式(取决于CPU架构)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.