1.4 Read,display and resize Image/Video

Eden.Yang·2023년 12월 6일
0

Computer VIsion

목록 보기
5/22

Mat imread( const string& filename, int flags=1)
•Flag value as 1:read image as color image
•Flag value as 0:read image as gray scale image

#include "opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main() {
	Mat gray_image, color_image;// 0 on the 2nd parameter means read imgin grayscale
    gray_image= imread("lena.png", 0); // blank 2nd parameter means 1, which means read imgin colors 
    color_image= imread("lena.png"); 
    return 0;

file에서 가져오기

#include “opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main() {
	Mat frame;
    VideoCapturecap;// check if file exists. if none program ends
    if (cap.open("background.mp4") == 0) {
      cout<< "no such file!" << endl;
      waitKey(0);
    }
    double fps = cap.get(CAP_PROP_FPS);
    double time_in_msec= cap.get(CAP_PROP_POS_MSEC); 
    int total_frames= cap.get(CAP_PROP_FRAME_COUNT);
 }

웹캠 가져오기

#include "opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main() {
Mat frame;
// capture from webcam
// whose device number=0
VideoCapturecap(0);
}

Display an image
•void imshow(const string &winname, InputArraymat)
•winname: Name of the window
•mat: image to be shown

#include "opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main() {
  Mat gray_image, color_image;// 0 on the 2nd parameter means read imgin grayscale
  gray_image= imread("lena.png", 0); // blank 2nd parameter means 1, which means read imgin colors 
  color_image= imread("lena.png"); 
  imshow("gray image", gray_image);
  imshow("color image", color_image);
  waitKey(0);
  return 0;
}

Resize an image

• resize(Mat src, Mat dst, Size(cols, rows)
• src: input image
• dst: output image
• Size(cols, rows) : Size of image to convert

#include "opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main() {
  Mat img= imread(“lena.png”);
  Mat resize_img;
  resize(img, resize_img, Size(200, 200));
  imshow(“original image”, img);
  imshow(“resize image”, resize_img);
  waitKey(0);
  return 0;
}
profile
손끝에서 땅끝으로, 골방에서 열방으로

0개의 댓글