728x90
반응형
OpenCV 에서 ROI 만큼 이미지를 Crop 시키는 방법은 아래와 같다.
간단한 방법인데, 잊지않으려고 정리한다.
Python 구현
# x, y, w, h refers to the ROI for which the image is to be cropped.
img = cv2.imread('test.jpg')
cropped_img = img[y: y + h, x: x + w]
C++ 구현
Mat img = cv::imread("test.jpg");
Rect bounds(0,0,img.cols,img.rows);
Rect r(x,y,width,height); // partly outside
Mat roi = img( r & bounds ); // cropped to fit image
위와 같이 구현하면 아래와 같은 에러를 방지함
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat
참고자료 : https://answers.opencv.org/question/179280/cropping-of-images-in-c-vs-python/
Cropping of images in c++ vs python - OpenCV Q&A Forum
Cropping of images in c++ vs python edit I got a strange error that I couldn't figure out where i went wrong.. I am trying to port from Python over to C++ the following cropping code: In Python: # x, y, w, h refers to the ROI for which the image is to be c
answers.opencv.org
728x90
반응형
'Development & Tools > Tools & Environments' 카테고리의 다른 글
[Linux] sudo apt-get -f install (0) | 2020.07.06 |
---|---|
[Linux] 리눅스 파티션 나누기 (0) | 2020.05.16 |
[Linux] 터미널 창에서 ctrl + s (0) | 2020.04.21 |
[Linux] 폴더 용량 크기 순서대로 확인하기 (0) | 2020.03.09 |
[Linux] Ubuntu에 Nvidia Driver 설치하기 (0) | 2020.01.22 |