c++ - 如何在 OpenCV 中将图像与另一个图像相关联

标签 c++ image opencv reflection

我在 OpenCV C++ 中做这个项目,我在其中制作给定图像的反射,就像翻转函数一样,但每个像素的坐标。问题是我得到的图像输出都是蓝色的,水平有一条线,我相信我的代码只影响第一个 channel 。

我试着做imageReflectionFinal.at<Vec3b>(r,c) = image.at<Vec3b>(r,c);为了解决它,但没有任何改变。我会在下面留下代码,在此先感谢。

    Mat image = imread("image_dir/image.jpg");
    Mat imageReflectionFinal = Mat::zeros(image.size(), image.type());
    for(unsigned int r=0; r<image.rows; r++) {
        for(unsigned int c=0; c<image.cols; c++) {
                imageReflectionFinal.at<Vec3b>(r,c) = image.at<Vec3b>(r,c);
                Vec3b sourcePixel = image.at<Vec3b>(r,c);
                imageReflectionFinal.at<Vec3b>(r, c) = (uchar)(c, -r + (220)/2);
        }
    }

最佳答案

如果您不想使用 flip函数,您可以镜像更改每行的 x 坐标(列)。这是代码:

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;

int main() {

    //You can change as "Mat3b" for the 3-channel images
    Mat1b image = imread("/ur/image/directory/image.jpg",CV_LOAD_IMAGE_GRAYSCALE);
    Mat1b imageReflectionFinal = Mat::zeros(image.size(), image.type());
    for(unsigned int r=0; r<image.rows; r++) {
        for(unsigned int c=0; c<image.cols; c++) {

            imageReflectionFinal(r, c) = image(r, image.cols - 1 - c);
            //y-axis(r) doesnt change only x-axis(cols) mirroring 
        }
    }

    imshow("Result",imageReflectionFinal);
    waitKey(0);
    return 0;
}

This answer is also my reference.

关于c++ - 如何在 OpenCV 中将图像与另一个图像相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60045476/

相关文章:

python - 使用 PIL 调整图像大小并保持方向

切换到 OpenCV 的自制程序后,Xcode 找不到 dylib

c++ - 类方法返回最后一个类,C++

c++ - 来自终端的base64编码字符串?

c++ - 为什么不能将 vector<bool> 中元素的地址推回 vector<bool*>?

css - Debug模式打开时的 Django 和静态文件

ios - 将图像处理转换为 64 位会创建黑线

c++ - 单元测试高度模板化的库

python - 打开简历流YouTube视频

opencv - cv::SVM 对每个样本响应一类