python 代码:
代码语言:javascript复制import cv2 as cv
src = cv.imread("./test.png")
cv.namedWindow("input", cv.WINDOW_AUTOSIZE)
cv.imshow("input", src)
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
cv.imshow("gray", gray)
cv.waitKey(0)
cv.destroyAllWindows()
C 代码:
代码语言:javascript复制#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int artc, char** argv) {
Mat src = imread("./test.png");
if (src.empty()) {
printf("could not load image...n");
return -1;
}
namedWindow("input", CV_WINDOW_AUTOSIZE);
imshow("input", src);
Mat gray;
cvtColor(src, gray, COLOR_BGR2GRAY);
imwrite("./gray.png", gray);
waitKey(0);
return 0;
}
OpenCV学习笔记代码,欢迎follow:
MachineLP/OpenCV-github.com