2023.10.17
Today's agenda
1. Open Image and Write Image
2. OpenCV primary class
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
using nsmaepsae cv; // if do not use cv all of opencv code need cv::
int main(){
Mat image = imread("/source/of/lenna.bmp");
if(image.empty()){ // Image load failed
cerr << "Image load failed" << "\n";
return -1;
}
imwrite("/source/of/filepath/for/image.bmp", image);
namedWindow("image"); // window named which image will show
imshow("image", image); // show image which opened to window
waitKey(); // wait for the key press from keyboard
destroyAllWindows(); // destroy all windows which opened
}
Mat imread(const String& filename, int flags = IMREAD_COLOR);
parameters
filename : path to filename to read(relative path can be applied)
flags : option flag for image read
IMREAD_UNCHANGED | read image from image's setting |
IMREAD_GRAYSCALE | read image for 1 channel grayscale |
IMREAD_COLOR | read image for 3 channel color |
return value : Mat type object variable
bool Mat::empty() const
return value : return 0 when rows, cols, data is 0
if data exist, return true
bool imwrite(const String &filename, InputArray img, const std::vector<int>& params = std::vector<int>());
void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);
void destroyWindow(const Strig& winname); void destroyAllWindows();
void imshow(const String& winname, InputArray mat);
void waitKey(int delay = 0);
** imshow() and waitKey() is almost pair of code. Actual image show is run after call waitKey()
Scala class
Mat class
1 channel n dimension or multi-channel matrix class
Using constructor size of matrix, data type, channel number and initial value can be declared
copy constructor, & operator run for swallow copy
Mat::copyTo(), Mat::clone() for deep copy
multiple four basic operation and << operator support
Mat class depth