Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | PointedEar | 1 | /*------------------------------------------------------------------------------------------*\ |
2 | This file contains material supporting chapter 1 of the cookbook: |
||
3 | Computer Vision Programming using the OpenCV Library. |
||
4 | by Robert Laganiere, Packt Publishing, 2011. |
||
5 | |||
6 | This program is free software; permission is hereby granted to use, copy, modify, |
||
7 | and distribute this source code, or portions thereof, for any purpose, without fee, |
||
8 | subject to the restriction that the copyright notice may not be removed |
||
9 | or altered from any source or altered source distribution. |
||
10 | The software is released on an as-is basis and without any warranties of any kind. |
||
11 | In particular, the software is not guaranteed to be fault-tolerant or free from failure. |
||
12 | The author disclaims all warranties with regard to this software, any use, |
||
13 | and any consequent failure, is purely the responsibility of the user. |
||
14 | |||
15 | Copyright (C) 2010-2011 Robert Laganiere, www.laganiere.name |
||
16 | \*------------------------------------------------------------------------------------------*/ |
||
17 | |||
18 | #include <iostream> |
||
19 | #include <opencv2/core/core.hpp> |
||
20 | #include <opencv2/highgui/highgui.hpp> |
||
21 | |||
22 | // function that creates and returns an image |
||
23 | cv::Mat function() { |
||
24 | |||
25 | // create image |
||
26 | cv::Mat ima(240,320,CV_8U,cv::Scalar(100)); |
||
27 | // return it |
||
28 | return ima; |
||
29 | } |
||
30 | |||
31 | int main() { |
||
32 | |||
33 | // create image |
||
34 | cv::Mat image; |
||
35 | // print image size |
||
36 | std::cout << "size: " << image.size().height << " , " |
||
37 | << image.size().width << std::endl; |
||
38 | // open image |
||
5 | PointedEar | 39 | image= cv::imread("baboon1.jpg"); |
3 | PointedEar | 40 | // check if image has been successfully read |
41 | if (!image.data) { |
||
5 | PointedEar | 42 | // no image has been created� |
3 | PointedEar | 43 | return 0; |
44 | } |
||
45 | // print image size |
||
46 | std::cout << "size (after reading): " << image.size().height << " , " |
||
47 | << image.size().width << std::endl; |
||
48 | |||
49 | // display image |
||
50 | cv::namedWindow("Original Image"); // define the window |
||
51 | cv::imshow("Original Image", image); // show the image |
||
52 | |||
53 | // create another image |
||
54 | cv::Mat result; |
||
55 | // flip the image |
||
56 | cv::flip(image,result,1); // positive for horizontal |
||
57 | // 0 for vertical, |
||
58 | // negative for both |
||
59 | // display result |
||
60 | cv::namedWindow("Output Image"); |
||
61 | cv::imshow("Output Image", result); |
||
62 | // wait for key pressed |
||
63 | cv::waitKey(0); |
||
64 | // write image on file |
||
65 | cv::imwrite("output.bmp", result); |
||
66 | |||
67 | // create two new images |
||
68 | cv::Mat image2, image3; |
||
69 | |||
70 | image2= result; // the two images refer to the same data |
||
71 | result.copyTo(image3); // a new copy is created |
||
72 | |||
73 | // flip vertically this time |
||
74 | cv::flip(result,result,0); |
||
75 | |||
76 | // display result |
||
77 | cv::namedWindow("image 2"); |
||
78 | cv::imshow("image 2", image2); |
||
79 | cv::namedWindow("image 3"); |
||
80 | cv::imshow("image 3", image3); |
||
81 | |||
82 | // get a gray-level image |
||
83 | cv::Mat gray= function(); |
||
84 | // display result |
||
85 | cv::namedWindow("Gray Image"); |
||
86 | cv::imshow("Gray Image", gray); |
||
87 | |||
88 | // wait for key pressed |
||
89 | cv::waitKey(0); |
||
90 | return 1; |
||
91 | } |
||
92 |