opencv-001-读取(imread)与显示(imshow)图像

知识点

  • 读取图像 - imread()
  • 显示图像 - imshow()

代码(c++,python)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main() {
// Mat image = imread("../images/liuyifei_1.png");
// 读取的时候加参数,使读取后为灰度图像
Mat image = imread("../images/liuyifei_1.png",IMREAD_GRAYSCALE);

if (image.empty()) {
cout << "could not load image..." << endl;
return -1;
}

namedWindow("input");
imshow("input",image);
waitKey(0);
return 0;
}
1
2
3
4
5
6
7
import cv2 as cv

src = cv.imread("../images/liuyifei_1.png")
cv.namedWindow("input", cv.WINDOW_AUTOSIZE)
cv.imshow("input", src)
cv.waitKey(0)
cv.destroyAllWindows()

结果

代码地址

github