Opencv learning: back to the original point! About some basic functions

 

opencv simple picture reading and display

1. Image reading

 Mat img = imread("C:/clip.png", 1);
 imshow("fang2", img);
 waitKey(0);

The image shows like this

 

2. Read and write pictures

    Mat img = imread("C:/clip.png", 1);
    imwrite("C:/clipcopy.jpg",img);
    waitKey(0);

The experiment seems to have failed, and no picture appears at the specified location. Considering that the C drive is protected by permissions, the file is now written to the E drive

imwrite("E:/clipcopy.png", img);

Successfully written, the picture is as follows

 

 3. The image is saved in different quality

    Mat img = imread("C:/clip.png", 1);
    vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
    compression_params.push_back(100);
    cv::imwrite("outImage.jpg", img, compression_params);
    imwrite("E:/clipcopy.png", img);
    imshow("sbsb", imread("E:/clipcopy.png"));
    waitKey(0);
    return 0;

There is a pit here, don't forget to define CV_IMWRITE_JPEG_QUALITY:

#define CV_IMWRITE_JPEG_QUALITY 1

 3. Pixel operation

 

Guess you like

Origin www.cnblogs.com/bigtwetwet/p/12709453.html