简体   繁体   English

OpenCV无法使用imwrite写入图像

[英]OpenCV unable to write Images using imwrite

I am trying to write a Mat format which I have created into a jpeg file but all I'm getting is an unhandled exception. 我正在尝试将我创建的Mat格式写入jpeg文件,但我得到的只是一个未处理的异常。 From the documentation it says that 从文档中可以看出来

Only 8-bit (or 16-bit unsigned (CV_16U) in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. 使用此功能时,只能保存8位(或PNG,JPEG 2000和TIFF情况下的16位无符号(CV_16U))单通道或3通道(带'BGR'通道顺序)图像。

So I created a Mat using the codes below: 所以我使用下面的代码创建了一个Mat:

Mat watermark(5,5,CV_16U);  
imwrite("C:\\watermark.jpg",watermark);

However, I am unable to write the image into jpeg. 但是,我无法将图像写入jpeg。 It works fine with BMP formats, but just not JPG or any other formats. 它适用于BMP格式,但不是JPG或任何其他格式。 I was advised to convert it to CV_16U or 8U but it didn't work as well and I do have write permissions to the C:\\ directory. 我被建议将其转换为CV_16U或8U,但它不能正常工作,我对C:\\目录有写权限。

Am I missing a step? 我错过了一步吗? Or is there some other way I should go about saving an image into JPG using OpenCV? 或者我还有其他方法可以使用OpenCV将图像保存到JPG中吗?

If you are using latest opencv (v3.0) or greater and windows x64 bit version some of opencv's functionality is not working correctly in debug mode... You have to run your code in release mode then everything will be run perfectly. 如果您使用的是最新的opencv(v3.0)或更高版本以及windows x64位版本,某些opencv的功能在调试模式下无法正常工作......您必须在发布模式下运行代码,然后一切都将完美运行。

Issues I found with opencv3.1 and x64 bit - debug mode 我在opencv3.1和x64位找到的问题 - 调试模式

  1. imwrite(filename, image) getting exception (read access violation). imwrite(filename,image)获取异常(读取访问冲突)。
  2. haarCascade.detectMultiScale(...) detects numerous amount of objects. haarCascade.detectMultiScale(...)检测到大量对象。

To fix these issues run application in release mode. 要解决这些问题,请在发布模式下运行应用程

Still searching a good way to solve these problems in debug mode. 仍在寻找一种在调试模式下解决这些问题的好方法。

This code works correct and make/rewrite "watermark.jpg": 此代码工作正常,并使/重写“watermark.jpg”:

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>

using namespace cv;

int main() {    
    Mat watermark(5,5,CV_16U);
    imwrite("C:\\watermark.jpg",watermark);
    return 0;
}

I have Win7, Wascana Eclipse(MinGW GCC compiler), Opencv 2.4.5 我有Win7,Wascana Eclipse(MinGW GCC编译器),Opencv 2.4.5

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

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