carloswc
老狗识屠
采纳率100%
2017-03-11 02:04 阅读 1.2k

求前辈指点:vs2015利用opencv库时存储图像问题

代码如下:
#include
using namespace std;

void main()
{
int r,c,i,j;
cv::Mat image1 = cv::imread("H:\C++projects\improcess_hw\2.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cv::imwrite("Photp_Cal_1.jpg",image1);
cv::namedWindow("IMAGE1");
cv::imshow("IMAGE1", image1);
cv::Mat image2 = cv::imread("H:\C++projects\improcess_hw\1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
r = image2.rows;
c = image2.cols;
for (i = 0;i < r;i++)
for (j = 0;j < c;j++)
image2.at(i,j)= 255-(image2.at(i, j));
cv::imwrite("Photp_Cal_2.jpg",image2);
cv::namedWindow("Image2");
cv::imshow("Image2", image2);
cv::waitKey();
}
提示错误
图片说明
如果保存为bmp就没有毛病,刚开始学,希望有前辈能够指点一点

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    fight_in_dl 战在春秋 2017-03-11 07:13

    查官方文档
    关于imread,imwrite函数支持的文件类型是这样描述的:

    • Windows bitmaps - *.bmp, *.dib (always supported)
    • JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)

    再看Notes section:

    On Microsoft Windows* OS and MacOSX*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs.

    从而得出结论,opencv需要包含libjpeg,这就涉及到编译opencv的问题,你可以用opencv build libjpeg为关键字搜索相关帮助。

    折腾,只有折腾才能进步......。

    点赞 1 评论 复制链接分享

相关推荐