Computer Vision - Experiment 1 - Image loading, display and output
Experimental objectives and requirements
(i) To master the installation of OpenCV in Windows through experiments;
(ii) master the method of loading, displaying and outputting images through experiments
Experiment content
(i) Installing OpenCV in Windows.
(ii) Write programs for loading, displaying and outputting images.
Experimental instruments, equipment
A computer with Windows 7 operating system and Visual Studio 2015 installed
Experimental principle
Opencv uses the Mat class to implement image storage. Images are stored in a matrix format where each pixel has a position and can be referenced by the number of columns and rows. the Mat class is not only used to store images, but also different types of matrices of arbitrary size. The Mat class can be used to perform operations such as matrix addition, matrix multiplication, matrix creation, etc. The imread function is used to read the image. imwrite function is used to write the image. imshow function is used to display the image.
Experimental steps
(i) Install OpenCV in Windows
Download opencv source code in the URL https://sourceforge.net/projects/opencvlibrary/ and install it in Windows to install OpenCV.
(ii) Configuring OpenCV in Visual Studio 2015;
(iii) Write code to read the image using the imread function;
(iv) Write code to write images using the imwrite function;
(v) Write code to display the image using the imshow function.
Experimental notes
(i) Configure OpenCV in VS after completing the installation of OpenCV;
(ii) The functions and usage of imread, imwrite, and imshow functions.
Experimental results
(i) Experimental code
|
|
(ii) Show results
Experiment Summary
The main content of this experiment is to write a program for loading, displaying and outputting images. The main functions used are cv::Mat girl=cv::imread(“xx.jpg”, 0); (load image to Mat, the first parameter xx.jpg is the name of the image, the second parameter 0 is the grayscale map); namedWindow(“window name”);; display function imshow(“window name”, xx);; load image function Mat image= imread(“xx.jpg”);; imageROI= image(Rect());; addWeighted();; imwrite(".jpg",image);;; etc. functions. This experiment allowed me to fully understand the above functions and the flow of the experiment. I learned how to use the above functions to load, display and input the most basic images by myself.