1

I started working with OPENCV and I firstly test some basic commands. At the moment I try to print out a particular value of a jpg image. I already read several posts and constructed the following C++ program.

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main()  //(int argc, char** argv)
{
    Mat image;
    image = imread("Desert.jpg", IMREAD_COLOR);
    cout << image.at<Vec3b>(1, 1)[0] << std::endl;
    cout << image.at<Vec3b>(1,1) << std::endl;
    image.at<Vec3b>(1, 1)[0] = 10;
    cout << image.at<Vec3b>(1, 1) << std::endl;
    return 0;
}

The output in the terminal is

▒
[205, 123, 51]  
[10, 123, 51]

So I get a strange value when printing out the first channel of pixel (1,1). Contrary to that I can print all three at once. I can even change the value of pixel (1,1) in channel 1 using the same syntax.

I use visual Studio and Vesion 3.4.1 of OPENCV. Any suggestions or comments why this happens?

4

1 回答 1

0

它打印的值看起来很糟糕,但实际上是正确的。

Vec3b类型是具有3 字节条目的向量,其中这些字节存储为无符号字符值以表示0 -> 255颜色范围。您在控制台中看到 205 的字节值。

Vec3b 对象最有可能重写了 << 以处理打印出供用户读取的值。

尝试将字节类型转换为 int 以查看值:

cout << (int)image.at<Vec3b>(1, 1)[0] << std::endl;
于 2018-07-11T15:28:13.663 回答