A mouse operation
1.cv::OnMouse()
void onMouse(int event,int x,int y,int flags,void* param);
void onMouse(int event,int x,int y,int flags,void* param){ cv::Mat* image=reinterpret_cast<cv::Mat*>(param); switch (event) {// scheduled events case CV_EVENT_LBUTTONDOWN: // left mouse button down event // display pixel values (x, y) std::cout<<static_cast<int>(image->at<unchar>(cv::Point(x,y)))<<std::endl; break; } } // Register the callback messages cv::setMouseCallback("Image",onMouse,reinterpret_cast<void*>(&image));
2.cvMouseCallback()
II. Keyboard
1.cv::waitKey()
2.cvWaitKey()
III. Drawing Operation
1.cv::circle
2.cv::Scalar
3.cv::putText
4.cv::rectangle
rectangle (image, cv :: Rect (0,0,100,200), cv :: Scalar (0,255,0), 2); // green box
IV. Read image
1.cv::imread()
Mat imread :: CV (const String & filename, the flags = int. 1)
(. 1) The first parameter is the image path, in the Windows operating system, the OpenCV imread function supports the following types of image loading:
Windows Bitmap - *. BMP, * .dib
JPEG files - * .jpeg, * .jpg, * .jpe
JPEG 2000 file - * .jp2
PNG picture - * .png
portable document format - * .pbm, .PGM *, * .ppm
Sun raster of Rasters file - .sr *, * .ras
TIFF files - * .tiff, * .tif
(2) The second parameter is the processing macro
IMREAD_UNCHANGED = -1, // read picture
IMREAD_GRAYSCALE = 0, // grayscale image
IMREAD_COLOR = 1, // the color image
IMREAD_ANYDEPTH = 2, // original image depth
IMREAD_ANYCOLOR = 4, // original color
2.cvLoadImage()
IplImage * cvLoadImage (const char * filename , int flags = CV_LOAD_IMAGE_COLOR);
first parameter:
"G: \\ \\ 1.jpg Image" to two backslashes
second argument:
CV_LOAD_IMAGE_COLOR By default, the image 8 is, in the form of three channels are read (the default image also makes cast channel 3)
CV_LOAD_IMAGE_GRAYSCALE cast single channel
CV_LOAD_IMAGE_ANGCOLOR holding places original image data is read into the passage way
CV_LOAD_IMAGE_ANYDEPTH image is a 16-bit image
CV_LOAD_IMAGEUNCHANGED that number of channels and the number of bits the read image and the original image consistent
-1 original image is read into the default channels
0 cast grayscale
1 reads color image
V. create a window / destroy the window
1.cv::namedWindow () / cv :: destoryWindow ()
2.cvNameWindow() / cvDestoryWindow()
VI. The image display
1.cv::imshow()
2.cvShowImage()
VII. Save the image
1.cvSaveImage()