process specific pixels from an image
d
How can i separate a specific region enclosed by the bounding box from the image and then process that specific region alone ??
d
How can i separate a specific region enclosed by the bounding box from the image and then process that specific region alone ??
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)
Not to be rude, but your code does way more than what he actually asked for. Also, keep in mind in the future, that if a sortlike solution is given, it is better to add a comment with remarks, then readd a similar answer...
Vec3b intensity = img.at<Vec3b>(y, x);
blue = intensity.val[0];
green = intensity.val[1];
intensity.val[2] = 128;//ya, I can write to the image this way
red = intensity.val[2];
This is possibly what you can do:
// This is pseudo-code, ofcourse you will need to change variable names with actual values or existing variables in your setup
// Region of interest - created manually or retrieved from somewhere
Rect bounding_box(x, y, width, heigth);
// Make a local copy of the region - do this to ensure you do not change the original image yet
Mat sub_region = original_image(bounding_box).clone();
// Perform something on this subregion --> for example apply Gaussian filter
GaussianBlur(sub_region, sub_region, Size(5,5), 0.0, 0.0, BORDER_DEFAULT );
// Copy the result back if you want it in your original image
sub_region.copyTo( original_image(bounding_box) );
Asked: 2014-01-18 02:09:06 -0600
Seen: 550 times
Last updated: Jan 24 '14
Licence plate detection with different backgrounds
How to train OCR to recognize characters?
openCV - anpr system. Improve success rate
Car detection. Best way. Like FreeFlow
Find lower border of objest using Brightness Histogram
Best solution for car approaching to the gate and anpr lib
How do I remove unwanted background edges for my ANPR project
How to detect the Licence plate?
is it good to train a classifier for each character in ANPR?
You mean something like this: http://stackoverflow.com/questions/16365129/opencv-howto-use-mask-parameter-for-feature-point-detection-surf
@JAyThaRevo never post links as solutions ... as they will possible disappear in the future this is not a good idea to make sure the solution is still available for other users when searching this forum. I will add a code snippet as answer.