파이썬 코드오류(color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor')

조회수 1532회

이미지를 이진화해서 텍스트로 뽑아내는 작업을 진행하는데 오류가 뜹니다.. 무슨문제가 있을까요 ?

import cv2 as cv

img_color = cv.imread('test.png', cv.IMREAD_COLOR) img_gray = cv.cvtColor(img_color, cv.COLOR_BGR2GRAY) ret, img_binary = cv.threshold(img_gray, 125, 255, cv.THRESH_BINARY) # 기준값 변화

height,width = img_binary.shape[:2]

f = open('i.txt', 'w')

for y in range(height): for x in range(width): print("%3d"%img_binary[y,x], end=" ") f.write("%3d " % img_binary[y,x]) print("") f.write("\n")

f.close() cv.imshow("Binary", img_binary) cv.imwrite('test.png' , img_binary) cv.waitKey(0)

코드에러 cv2.error: OpenCV(3.4.5) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • 코드 부분의 시작과 끝은 백쿼테이션 마크 ```으로 표시해 가독성 있게 만들어주어야 답변하시는 분들이 더 편할듯. 알 수 없는 사용자 2019.5.10 10:26

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)