Point-to-point operation on image

Asked

Viewed 72 times

1

I am trying to perform a simple sum operation that adds 30 to the intensities on each channel, but the program only hangs without error output (probably some type error).

I hit that reply

// Codigos1.cpp : define o ponto de entrada para o aplicativo do console.
//

#include "stdafx.h"


#include < opencv2/opencv.hpp >

#include < iostream >

#include < opencv2/imgproc/imgproc.hpp >


using namespace cv;

using namespace std;

Vec3b logPoint(Vec3b RGB) {
    Vec3b res;
    res[0] = RGB[0]+30;
    res[1] = RGB[1]+30;


    return res;
}

int main(int argc, char** argv)
{


    //ABRE A IMAGEM->CINZA e MOSTRA
    Mat img = imread("img.jpg", IMREAD_GRAYSCALE);
    Mat dest(img.size().width, img.size().height,CV_8SC1);



    for (int i = 0; i-1 < img.rows; i++) {
        for (int j = 0; j-1 < img.cols; j++) {
            Vec3b pixel = img.at<Vec3b>(i,j);
            dest.at<Vec3b>(i, j) = logPoint(pixel);

            //cout << logPoint(pixel)[0] << "|" << logPoint(pixel)[1]<<endl;

        }
    }

    namedWindow("img", WINDOW_AUTOSIZE);
    imshow("img", img);
    if(waitKey(0) == 27) destroyAllWindows();


    return 0;
}

1 answer

3


Try to do it like this inside for:

Vec3b pixel = img.at<Vec3b>(i,j);
Vec3b result = logPoint(pixel);
dest.at<Vec3b>(i,j)[0] = result[0];
dest.at<Vec3b>(i,j)[1] = result[1];
dest.at<Vec3b>(i,j)[2] = result[2];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.