使用C ++使用opencv覆盖

时间:2018-09-15 19:51:24

标签: c++ opencv

我的问题是关于尝试固定斜线,以便我的覆盖层可以正常工作,并且基于条件语句,白色像素代替了黑色像素。我已经尝试了几种方法,例如使用不同的类型,例如:

                out1.at<Vec3b>(i,j)[0]=image.at<Vec3b>(i,j)[0]; 
                out1.at<Vec3b>(i,j)[1]=image.at<Vec3b>(i,j)[1]; 
                out1.at<Vec3b>(i,j)[2]=image.at<Vec3b>(i,j)[2];

但是我遇到了堆错误。我相信我真的很亲密,但是我需要一些建议或指导。请原谅我所做的任何错误,因为这是我的第一篇文章。

这是我的代码。

#include <iostream>
#include <stdint.h>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"

using namespace std;
using namespace cv;


int main(int argv, char** argc)
{
Mat image; // new blank image
Mat image2;
Mat out1;

image2 = cv::imread("test2.bmp",CV_LOAD_IMAGE_GRAYSCALE); // read the file
image = cv::imread("test1.bmp",CV_LOAD_IMAGE_GRAYSCALE);


if (!image.data) // error handling if file does not load
{
    cout<< "Image 1  not loaded";
    return -1;
}
if (!image2.data)
{
    cout << "Image 2 not loaded";
    return -1;
}

// resize images to make sure all images is the same size
cv::resize(image2, image2, image.size());
cv::resize(image2, out1, image.size());
// copying content of overlay image to output file
//image2.copyTo(out1);
out1 = image2.clone();
// for loop comparing pixels to original image
for (int i =0; i < out1.rows; i++)
{
        for(int j =0; j < out1.cols; j++)
        {
            //Vec3b color = image.at<Vec3b>(Point(i,j));
            if(out1.at<uchar>(i,j)==0 && out1.at<uchar>(i,j) ==0 && 
            out1.at<uchar>(i,j)==0)
            {
                out1.at<Vec3b>(i,j)[0]=255; // blue channel
                out1.at<Vec3b>(i,j)[1]=255; // green channel
                out1.at<Vec3b>(i,j)[2]=255; // red channel
            }
              else
               *out1.at<uchar>(i,j) = image.at<uchar>(i,j);*
        }
  }


  cv::imwrite("out1.bmp",out1);  // save to output file



    namedWindow("Display window", CV_WINDOW_AUTOSIZE);// creat a window to  
     display w/label
    imshow("Display window",out1); // show image inside display window

   waitKey(0);
   return 0;
}

我的图像即将正确覆盖。我的问题是 由于我的某行,像素显示黑色而不是白色 程序

0 个答案:

没有答案