Load, change and save pictures.
- LOAD IMAGE -> cv::imread
- CHANGE IMAGE -> cv::cvtColor
- SAVE IMAGE -> cv::imwrite
Load a picture file as a ‘Mat’ object.
FIRST: image file name
SECOND: type of current image file
IMREAD_UNCHANGED(<0) -> load the origin image, no any changes.
IMREAD_GRAYSCALE(0) -> load the gray scale image.
IMREAD_COLOR(>0) -> load the RGB image. (DEFAULT)
Create an opencv window which is created and released automatically, we don’t need to destroy it.
namedWindow(“Window Title”, WINDOW_AUTOSIZE);
WINDOW_AUTOSIZE will auto resize the window according to the size of image, but cannot be resized by manually.
WINDOW_NORMAL when use it and integrated with QT, it can be adjusted the window size.
Display the image to the window according to the window title.
FIRST: window title
SECOND: Mat Object
It can switch the color space to the another, it has three argument.
FIRST: origin image
SECOND: changed image
THREE: origin and color space of target, for example, COLOR_BGR2HLS , COLOR_BGR2GRAY etc.
cvtColor(image, gray_image, COLOR_BGR2GRAY);
Save current image file to the fixed path.
Only the BGR image of png, jpg, tiff file of 8 bit or 16 bit which is single channel or three channels can be saved by this way.
When saving the png file, it can save the transparency channel images.
We can specify the compress arguments.
FIRST: output file path and name
SECOND: the Mat Object which will be saved
Get the pointer of image pixel.
CV_Assert(myImage.depth() == CV_8U);
Mat.ptr<uchar>(int i=0) -> Get the pointer of pixel matrix, the index i express the number of lines, count from zero.
const uchar* current=myImage.ptr<uchar>(row); -> Get the current line pointer.
p(row, col)=current[col] -> Get the value of pixel of current pixel point P(row, col).