Today to a company to communicate, learned that they are doing an assembly line of testing equipment, the request is how to achieve a picture of the specified area of the operation of the pixel value, how to add text in the picture, because the company to the coding environment is VC, use it is not accustomed to, at night to ponder this matter, after many references, Probably implemented the process and pasted the code below.
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/stitching/stitcher.hpp>
using namespace Std;
using namespace CV;
The main purpose of the code is to implement the pixel action in the picture, add text in the picture display area.
int main ()
{
Iplimage *orig=cvloadimage ("1.jpg");
Cvnamedwindow ("orig", 0); Cvshowimage ("orig", orig);//Display Original
for (int i = 0; i < orig->height; i++)
{
for (int j = 0; J < orig->width/2; J + +)//reduce 20 grayscale levels for the left half of the original image
{
Cvscalar p = cvget2d (orig, I, j);//Get 3 channels per pixel point
P.val[0] = p.val[0]-20;
P.VAL[1] = p.val[1]-20;
P.VAL[2] = p.val[2]-20;
CVSET2D (Orig, I, J, p);//corrected brightness to re-assign this pixel point
}
for (int j = orig->width/2; J < orig->width; + +)//Add 20 gray levels to the right half of the original image
{
Cvscalar p = cvget2d (orig, I, j);
P.val[0] = p.val[0] + 20;
P.VAL[1] = p.val[1] + 20;
P.VAL[2] = p.val[2] + 20;
CVSET2D (Orig, I, J, p);
}
}
Cvnamedwindow ("Adjust", 0); Cvshowimage ("Adjust", orig);//Display the picture after the left and right Pixel point operation
Cvfont font;//The property used to hold the text font
Cvinitfont (&font, Cv_font_hershey_simplex, 3,3,1,2,8);
In the picture orig [122,230] The pixel out shows black "Hello world!", font format
Cvputtext (Orig, "Hello world!", Cvpoint (122,230), &font, cvscalar (0, 0, 0));
Cvnamedwindow ("text", 0); Cvshowimage ("text", orig);
Cvwaitkey (0);
return 0;
}