본문 바로가기

Python/OpenCV

(4)
cv2.error: OpenCV(4.5.4) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\clahe.cpp:353: error: (-215:Assertion failed) _src.type() == CV_8UC1 || _src.type() == CV_16UC1 in function '`anonymous-namespace'::CLAHE_Impl::apply' ___해결못하고 코드 자체를 다른 걸 사용했다 ___ image1 =scan_img(image ,width=200,ksize=(3,3), min_threshold=20,max_threshold=210) image2 = img_roi(image1) gray = cv2.cvtColor(np.float32(image2), cv2.IMREAD_GRAYSCALE) gray = cv2.normalize(gray, None, 0, 255, cv2.NORM_MINMAX) chahe = cv2.createCLAHE(clipLimit=1.0, tileGridSize=(5, 5)) gray = chahe.apply(gray) 아마 이 코드에서 float32로 변환해서 에러가 난것같다. 다른 프로젝트를 하다가 이런 에러를 또..
gray = cv2.cvtColor(np.float32(image2), cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.5.4) d:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function '__cdecl cv::impl::`anonymous-namespace.. image1 =scan_img(image ,width=200,ksize=(3,3), min_threshold=20,max_threshold=210) image2 = img_roi(image1) gray = cv2.cvtColor(np.float32(image2), cv2.COLOR_BGR2GRAY) 에서 밑의 코드로 변경하니 해결 되었다. image1 =scan_img(image ,width=200,ksize=(3,3), min_threshold=20,max_threshold=210) image2 = img_roi(image1) gray = cv2.cvtColor(np.float32(image2), cv2.IMREAD_GRAYSCALE)
이미지 속성 OpenCV에서 이미지를 다룰때 이미지 속성을 잘 이해하면 다루기 쉽다. 그러기 위해선 Numpy가 선행되어야한다. 포스팅은 안했지만 나는 numpy에 대해서 알기 때문에 numpy 설명은 pass하겠다. ​ ​ 우선 cv2와 numpy를 import 한다. ​ 객체 img는 다차원 배열 (numpy narray)이다. ​ 독수리 사진을 불러와서 img로 객체를 저장해보고 img.shape, img.size, img.dtype을 살펴보자! ​ img.shape : 이미지 해상도 및 채널 수 (height, width, channel) img.size : 이미지 크기 (byte 단위) img.dtype : 이미지 데이터 타입 ​ ※ 수학적인 분석을 할 때 보통 (x,y) 구조가 익숙하기에 헷갈릴 수 있는데..
OpenCV로 이미지 불러오고 출력하고 저장하기 OpenCV란? Open source로 Computer Vision library + 크로스플랫폼과 실시간 이미지 프로세싱에 중점을 둔 라이브러리 컴퓨터 비전 = 카메라로 얻은 일련의 영상들, 기본이미지 import cv2 로 다운받은 open cv를 이용해서 이미지를 처리할 수 있다. 우선 이미지를 읽어오는 것 , 화면에 출력하는 것 , 저장하는 것을 확인해보자. ● cv2.imread(file_name, flg) : 이미지를 읽어 Numpy 객체로 만드는 함수 file_name = 읽어올 이미지 파일 flag = 이미지를 어떤 방법으로 읽어 올 건지 정해줌 : IMREAD_COLOR = 1 -> alpha 채널, 즉 투명한 부분은 무시하고 컬러 채널 3개 모두 가져와 BGR컬러이미지로 읽어온다. IM..