为什么mat在读取灰色图像时始终会得到负值

时间:2017-08-17 00:32:10

标签: opencv

当我读取灰色图像时,我总是得到负灰色值,如下所示:

-1246382668 -1246382667 -1246382667 -1246382667 -1263028297 -1296911180 -1280068686 -1246382667 -1280068171 -1330597709 -1229539658 -1229539658 -1229539658 -1263159883 -1263225676 -1280068684 -1263225676 -1280068428 -1280068685 -1330466126 -1347440464 -1364283729 -1313688910 -1313754703 -1313754703 -1296977487 -1296911694 -1280068686 -1212762442 -1195853897 -1195853640 -1179010631 -1179010631 -1179010631 -1195919433 -1195853640 -1195853640 -1263094090 -1296911180 -1330597710 -1280200271 -1229540429 -1162167626 -1094861379 -1145323842 -1195853637 -1195919433 -1179010888 -1179010631 -1128613190 -1077953348 -1044266561 -960512065 -791623994 -673720368 -639968550 -690562599 -741092394 -926036531 -1061107512 -1162167616 -1212630856 -1212696649 -1212696649 -1212630856 -1246382153 -1263225675 -1229671244

为什么?

图片如下: infrared walker picture

代码如下:

//将图片数据存入opencv结构体中。

QTextCodec* code = QTextCodec::codecForName("gb18030");

std::string name = code->fromUnicode(fileName).data();

m_cvImageTobeProcessed = cv::imread(name);

1 个答案:

答案 0 :(得分:0)

尝试使用cv :: imread。

的API

(见:http://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html

此调用会将图像加载为灰度(这可能是您想要的?)

cv::imread(filePath, cv::CV_LOAD_IMAGE_GRAYSCALE)

读取图像的默认设置为IMREAD_COLOR,尝试读取  图像并将其转换为3通道BGR彩色图像。这可能会导致问题......