gpt4 book ai didi

opencv - 创建的图像无法正确显示

转载 作者:行者123 更新时间:2023-12-02 16:40:26 25 4
gpt4 key购买 nike

您好我正在使用以下功能来创建图像。

垫 im(584, 565, CV_8UC1, imgg);
imwrite("Output_Image.tif", im);

但问题是当我显示图像“Output_Image.tif”时。右手边部分与左手边部分重叠。我无法理解发生了什么。请解释一下,因为我是opencv的初学者。谢谢 This is the Output_image.tiff

最佳答案

你确定图像是CV_8UC1(colospace grayscale)吗?

看起来图像是 BGR 图像(蓝色、绿色、红色),当您使用 CV_8UC3 图像作为 CV_8UC1 图像时,它会这样做。

更改此行:

 Mat im(584, 565, CV_8UC1, imgg);

到这一行:
Mat im(584, 565, CV_8UC3, imgg);

编辑 mixChannels() (见评论):

C++: void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs)

Mat* dst 是一个 Mats 数组,在调用 mixChannels 之前必须分配正确的大小和深度。在该数组中,您的 cv::Mats 将真正有 1 个 channel 。

代码示例:
cv::Mat rgb(500, 500, CV_8UC3, cv::Scalar(255,255,255));
cv::Mat redChannel(rgb.rows, rgb.cols, cv_8UC1);
cv::Mat greenChannel(rgb.rows, rgb.cols, cv_8UC1);
cv::Mat blueChannel(rgb.rows, rgb.cols, cv_8UC1);

cv::Mat outArray[] = {redChannel, greenChannel, blueChannel };

int from_to[] = {0,0 , 1,2 , 3,3};
cv::mixChannels(&rgb, 1, outArray, 3, from_to, 3);

它比 split() 函数复杂一点,所以这里有一个文档的链接,尤其是 from_to 数组一开始很难理解

文档链接:
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#mixchannels

关于opencv - 创建的图像无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24839124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com