Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi,

I am new to OpenCV. I was thinking my be you could hit the pixels you want with this program:


#include<opencv2/highgui/highgui.hpp>

#include<stdio.h>

#include<iostream>

using namespace cv; using namespace std;

int main() { Mat img = imread("red.jpg",CV_LOAD_IMAGE_COLOR);

unsigned char *input = (unsigned char*)(img.data);
unsigned int i,j,r,g,b;
unsigned int r_Old,g_Old,b_Old;
unsigned int r_average,g_average,b_average;
uchar blue, green, red;

// dead center image read of a pixels of my image.jpg

unsigned int y, x;

y = 300;
x = 300;
Vec3b intensity = img.at<Vec3b>(y, x);

//The same method can be used to change pixel intensities: img.at<uchar>(y, x) = 128; //have not written to image yet.

blue = intensity.val[0];
green = intensity.val[1];
red = intensity.val[2];

b_Old = blue;
g_Old = green;
r_Old = red;

cout << "\n";
cout << "b_Old " << b_Old << "\n";
cout << "g__Old " << g_Old << "\n";
cout << "r__Old " << r_Old << "\n";

    b_average = b_Old;
    g_average = g_Old;
    r_average = r_Old;

// i scaned the whole screen and averaged for an average color value:

for( y = 0;y < img.rows;y++)
{
for( x = 0;x < img.cols;x++)
    {

Vec3b intensity = img.at<Vec3b>(y, x);
blue = intensity.val[0];
green = intensity.val[1];
red = intensity.val[2];

        b_average = b_average + blue;
        g_average = g_average + green;
        r_average = r_average + red;

        }

    }
cout << "\n";

b_average = b_average/(img.rows * img.cols);
g_average = g_average/(img.rows * img.cols);
r_average = r_average/(img.rows * img.cols);

cout << "b_average " << b_average << "\n";
cout << "g_average " << g_average << "\n";
cout << "r_average " << r_average << "\n";
cout << "img.rows " << img.rows << "\n";
cout << "img.cols " << img.cols << "\n";

return 0;

}


"g++ -ggdb pkg-config --cflags opencv -o basename p.cpp .cpp p.cpp pkg-config --libs opencv"

http://docs.opencv.org/doc/user_guide/ug_mat.html

"g++ p.cpp -o p pkg-config --cflags --libs opencv"

Worked on Mint Linux 14 in the terminal.

green.jpg(/upfiles/13905252524741347.jpg)(/upfiles/13905252303553609.jpg)

Hi,

I am new to OpenCV. I was thinking my be you could hit the pixels you want with this program:


#include<opencv2/highgui/highgui.hpp>

#include<stdio.h>

#include<iostream>

`#`include`<opencv2/highgui/highgui.hpp>` `#`include`<stdio.h>` `#`include`<iostream>` using namespace cv; using namespace std;

std; int main() { Mat img = imread("red.jpg",CV_LOAD_IMAGE_COLOR);

imread("red.jpg",CV_LOAD_IMAGE_COLOR);

    unsigned char *input = (unsigned char*)(img.data);
 unsigned int i,j,r,g,b;
 unsigned int r_Old,g_Old,b_Old;
 unsigned int r_average,g_average,b_average;
 uchar blue, green, red;

// dead center image read of a pixels of my image.jpg

image.jpg unsigned int y, x;

x;

    y = 300;
 x = 300;
 Vec3b intensity = img.at<Vec3b>(y, x);

//The same method can be used to change pixel intensities: img.at<uchar>(y, x) = 128; //have not written to image yet.

yet.


    blue = intensity.val[0];
 green = intensity.val[1];
 red = intensity.val[2];

 b_Old = blue;
 g_Old = green;
 r_Old = red;

cout << "\n";
    cout << "\n";
    cout << "b_Old " << b_Old << "\n";
 cout << "g__Old " << g_Old << "\n";
 cout << "r__Old " << r_Old << "\n";

     b_average = b_Old;
     g_average = g_Old;
     r_average = r_Old;

// i scaned the whole screen and averaged for an average color value:

value:


    for( y = 0;y < img.rows;y++)
 {
 for( x = 0;x < img.cols;x++)
     {

 Vec3b intensity = img.at<Vec3b>(y, x);
 blue = intensity.val[0];
 green = intensity.val[1];
 red = intensity.val[2];

         b_average = b_average + blue;
         g_average = g_average + green;
         r_average = r_average + red;

         }

     }
cout << "\n";

    cout << "\n";

    b_average = b_average/(img.rows * img.cols);
 g_average = g_average/(img.rows * img.cols);
 r_average = r_average/(img.rows * img.cols);

 cout << "b_average " << b_average << "\n";
 cout << "g_average " << g_average << "\n";
 cout << "r_average " << r_average << "\n";
 cout << "img.rows " << img.rows << "\n";
 cout << "img.cols " << img.cols << "\n";

 return 0;
}

}


"g++

g++ -ggdb pkg-config `pkg-config --cflags opencvopencv` -o `basename p.cpp .cpp` p.cpp `pkg-config --libs opencv`
 -o basename p.cpp .cpp p.cpp pkg-config --libs opencv" 

http://docs.opencv.org/doc/user_guide/ug_mat.html

"g++

g++ p.cpp -o p pkg-config `pkg-config --cflags --libs opencvopencv`
"

Worked on Mint Linux 14 in the terminal.

green.jpg(/upfiles/13905252524741347.jpg)(/upfiles/13905252303553609.jpg)