如何使用C ++在OpenCV中显示图像元数据?

时间:2019-07-20 10:18:39

标签: c++ opencv image-processing metadata ubuntu-18.04

我想选择一个图像并使用opencv和c ++显示其元数据,例如高度,宽度,rgb值,格式等。我该怎么办?

1 个答案:

答案 0 :(得分:1)

方法一:

如果要使用代码了解图像的高度,宽度和rgb值,可以使用:

Mat img = imread("image.jpg");
cout<< "Width:" << img.cols << "Height:" << img.rows << endl; // width and height
cout<< img.at<cv::Vec3b>(i,j)[0] << endl; // This code gives you the pixel value of a chosen coordinate.
//i and j are your coordinates. and 0 represents the first layer of BGR 
//values. You can change it with 1 or 2 to learn the other layer values

方法II:

如果要使用屏幕学习所需的值,则可以简单地使用opencv的“ imshow”功能。在屏幕上,您可以找到宽度和高度。您还可以使用鼠标来学习任意一点的rgb值。 (您可以使用鼠标缩放任意点)