Pixel manipulation of pictures, adding text

Source: Internet
Author: User

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;
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.