opencv C++图像读取
发布时间:2020-12-16 09:16:40 所属栏目:百科 来源:网络整理
导读:int main(){ cv::Mat img =cv::imread( " /home/nan/图片/highdeepth/starry.jpg " ,cv::IMREAD_REDUCED_COLOR_8); // imread( const String filename,int flags = IMREAD_COLOR ); if (img.empty()) return - 1 ; cv::imshow( " BGR " ,img); std::vector c
int main(){ cv::Mat img=cv::imread("/home/nan/图片/highdeepth/starry.jpg",cv::IMREAD_REDUCED_COLOR_8); // imread( const String& filename,int flags = IMREAD_COLOR ); if(img.empty()) return -1; cv::imshow("BGR",img); std::vector<cv::Mat> planes; cv::split(img,planes); cv::imshow("B",planes[0]); cv::imshow("G",planes[1]); cv::imshow("R",planes[2]); cv::imshow("BGR",img); img=cv::imread("/home/nan/图片/highdeepth/starry.jpg",cv::IMREAD_REDUCED_GRAYSCALE_8); cv::split(img,planes); // 灰度图只能分离出一个通道 cv::imshow("Gray",planes[0]); cv::waitKey(0); return 0; } 注意:如果图像像素过大,并且要读出全部图像的话可以使用尺寸缩减 如:cv::IMREAD_REDUCED_COLOR_8。 flags包括以下内容: IMREAD_UNCHANGED = -1,//!< If set,return the loaded image as is (with alpha channel,otherwise it gets cropped). IMREAD_GRAYSCALE = 0,always convert image to the single channel grayscale image. IMREAD_COLOR = 1,always convert image to the 3 channel BGR color image. IMREAD_ANYDEPTH = 2,return 16-bit/32-bit image when the input has the corresponding depth,otherwise convert it to 8-bit. IMREAD_ANYCOLOR = 4,the image is read in any possible color format. IMREAD_LOAD_GDAL = 8,use the gdal driver for loading the image. IMREAD_REDUCED_GRAYSCALE_2 = 16,always convert image to the single channel grayscale image and the image size reduced 1/2. IMREAD_REDUCED_COLOR_2 = 17,always convert image to the 3 channel BGR color image and the image size reduced 1/2. IMREAD_REDUCED_GRAYSCALE_4 = 32,always convert image to the single channel grayscale image and the image size reduced 1/4. IMREAD_REDUCED_COLOR_4 = 33,always convert image to the 3 channel BGR color image and the image size reduced 1/4. IMREAD_REDUCED_GRAYSCALE_8 = 64,always convert image to the single channel grayscale image and the image size reduced 1/8. IMREAD_REDUCED_COLOR_8 = 65,always convert image to the 3 channel BGR color image and the image size reduced 1/8. IMREAD_IGNORE_ORIENTATION = 128 //!< If set,do not rotate the image according to EXIF‘s orientation flag. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |