我需要使用 opencv 和 c++ 以不同格式保存图像。
有一个用于显示图像的代码,并在按下某个键时退出。
显示 jpeg 图像的可能格式是什么?如何显示?
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
waitKey(0);
return 0;
}
最佳答案
根据OpenCV doc :
函数 imread 从指定文件加载图像并返回。如果无法读取图像(由于缺少文件、权限不正确、格式不受支持或无效),该函数将返回一个空矩阵 (Mat::data==NULL
)。目前,支持以下文件格式:
备注
备注
在彩色图像的情况下,解码图像的 channel 将以 B G R 顺序存储。
关于c++ - 开放式简历中的图像格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32635549/