Example 3-12 ...... Example 3-15 opencv

Source: Internet
Author: User

// Example 3-12 use imageroi to increase the pixel value in a certain range </P> <p> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> int main (INT argc, char ** argv) <br/>{< br/> iplimage * SRC; <br/> If (argc = 7 & (src = cvloadimage (argv [1], 1 ))! = 0) <br/>{< br/> int x = atoi (argv [2]); <br/> int y = atoi (argv [3]); <br/> int width = atoi (argv [4]); <br/> int Height = atoi (argv [5]); <br/> int add = atoi (argv [6]); <br/> cvsetimageroi (SRC, cvrect (X, Y, width, height )); <br/> cvadds (SRC, cvscalar (ADD), Src); <br/> cvresetimageroi (SRC); <br/> cvnamedwindow ("roi_add", 1 ); <br/> cvshowimage ("roi_add", Src); <br/> cvwaitkey (0); <br/>}< br/> return 0; <br/>}< br/> Note: </P> <p> the input parameter is D: /try0621/3-12/debug> 3-12.exe B .jpg 660 180 100 100 150 </P> <p> // another method for increasing the pixel value in 3-13 Examples </P> <p> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> cvnamedwindow ("ha "); <br/> iplimage * interest_img = cvloadimage (argv [1], 1); <br/> cvshowimage ("interest_img", interest_img ); <br/> cvrect interest_rect = cvrect (300,500,200,200); <br/> iplimage * sub_img = Cvcreateimageheader (cvsize (bytes, interest_rect.height), interest_img-> depth, interest_img-> nchannels); <br/> // cvshowimage ("sub_img", sub_img ); // This is not suitable for output. <br/> sub_img-> origin = interest_img-> origin; <br/> sub_img-> widthstep = interest_img-> widthstep; <br/> sub_img-> imagedata = interest_img-> imagedata + interest_rect.y * interest_img-> widthstep + interest_rect.x * interest_img-> nchannels; printf ("her E "); <br/> cvadds (sub_img, cvscalar (50), sub_img); <br/> cvshowimage (" ", sub_img ); <br/> cvwaitkey (0); <br/> cvreleaseimageheader (& sub_img); <br/> cvreleaseimage (& interest_img); <br/> cvdestroywindow ("La "); <br/> return 0; <br/>}< br/> note: <br/> Add pixels </P> <p> // Example 3-14 </P> <p> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> iplimage * src1, * s RC2; <br/> // If (argc = 9 & (src1 = cvloadimage (argv [1], 1 ))! = 0) & (src2 = cvloadimage (argv [2], 1 ))! = 0) <br/>{< br/> src1 = cvloadimage (argv [1], 1); <br/> src2 = cvloadimage (argv [2], 1); <br/> // int x = atoi (argv [3]); <br/> // int y = atoi (argv [4]); <br/> // int width = atoi (argv [5]); // 200 <br/> // int Height = atoi (argv [6]); // 100 <br/> // double alpha = (double) atof (argv [7]); <br/> // double Beta = (double) atof (argv [8]); <br/> cvsetimageroi (src1, cvrect (500,350,280,150); <br/> cvsetimageroi (src2, cvrect (380,190,280,150); <br/> Cvaddweighted (src1, 0.3, src2, 0.7, 0.0, src1); <br/> cvresetimageroi (src1); <br/> cvnamedwindow ("alpha_blend", 1 ); <br/> cvshowimage ("alpha_blend", src1); <br/> cvwaitkey (); <br/>}< br/> return 0; <br/>}< br/> // another exercise <br/> int main (INT argc, char ** argv) <br/>{< br/> cvnamedwindow ("image superposition", 1); <br/> iplimage * src1, * src2; // src1 = src1 + src2. The ROI must be the same size </P> <p> src1 = cvloadimage (argv [1], 1); <br/> cvsetimageroi (src1, cvrect (400,300,280,150); // Covered Area <br/> cvshowimage ("src1", src1 ); </P> <p> src2 = cvloadimage (argv [2], 1); <br/> cvsetimageroi (src2, cvrect (380,190,280,150 )); // Filled Area <br/> cvshowimage ("src2", src2); </P> <p> cvaddweighted (src1, 0.3, src2, 0.7, 0.0, src1); <br/> cvresetimageroi (src1); <br/> cvshowimage ("generated target image", src1); </P> <p> cvwaitkey (0 ); <br/> r Eturn 0; <br/>}</P> <p> note: </P> <p> it is very difficult to find the desired region. <br/> cvrect (horizontal axis of the start point, vertical axis of the start point, width, and height) <br/> cvaddweighted (addition 1, addition 1 coefficient, Addition 2, Addition 2 coefficient, gamma, generated target image) <br/> the generated target image is generally a addition of 1 </P> <p> // Example 3-15 store and read cvmat-use XML files </P> <p> // 3-15 store and read cvmat. CPP: defines the entry point of the console application. <Br/> // </P> <p> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> float the_matrix_data [] = {1, 2, 3, 4, ,}; <br/> cvmat A = cvmat (, cv_32f, the_matrix_data); <br/> cvsave ("my_matrix.xml ", & A); </P> <p> cvmat * a1 = (cvmat *) cvload ("my_matrix.xml"); </P> <p> printf ("% F ", cvget2d (A1, 1, 1); <br/> return 0; <br/>}</P> <p> // generated XML file Parts: <br/> <? XML version = "1.0"?> <Br/> <opencv_storage> <br/> <my_matrix type_id = "opencv-matrix"> <br/> <rows> 4 </rows> <br/> <Cols> 4 </Cols> <br/> <DT> F </DT> <br/> <DATA> <br/> 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. <br/> </data> <br/> </my_matrix> <br/> </opencv_storage> </P> <p> Notes: </P> <p> I hope to learn XML <br/>.

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.