일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- WSSS
- 기초확률론
- CellPin
- Decision Boundary
- 도커
- vscode
- 히비스서커스
- cocre
- numpy
- docker exec
- 프로그래머스
- ssh
- aiffel exploration
- AIFFEL
- 사회조사분석사2급
- Pull Request
- docker
- GIT
- cs231n
- logistic regression
- docker attach
- HookNet
- 코크리
- IVI
- airflow
- 오블완
- Jupyter notebook
- Multi-Resolution Networks for Semantic Segmentation in Whole Slide Images
- 백신후원
- 티스토리챌린지
Archives
- Today
- Total
히비스서커스의 블로그
[Opencv] error: OpenCV(4.5.4) /tmp/pip-req-build-sokf1_ny/opencv/modules/imgproc/src/contours.cpp:195: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise s.. 본문
Programming/Python
[Opencv] error: OpenCV(4.5.4) /tmp/pip-req-build-sokf1_ny/opencv/modules/imgproc/src/contours.cpp:195: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise s..
HibisCircus 2022. 1. 3. 17:31728x90
상황
np.where 후 cv2.findContours을 해주었더니 에러가 발생하였다.
대략적인 코드
import numpy as np
import cv2
mask = np.zeros((300,300))
pts1 = [np.array([(100, 200), (100, 200), (200, 200), (200, 100)], dtype=np.int32)]
cv2.drawContours(mask, pts1, -1, 2.5, 10)
cv2.findContours(mask, ,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
에러메시지
error: OpenCV(4.5.4) /tmp/pip-req-build-sokf1_ny/opencv/modules/imgproc/src/contours.cpp:195: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'
원인
np.where 후 데이터 타입을 지정해주지 않았기 때문이다.
해결방법
np.where 후 astype(np.uint8)로 데이터 타입을 지정해준다.
수정된 코드
import numpy as np
import cv2
mask = np.zeros((300,300))
pts1 = [np.array([(100, 200), (100, 200), (200, 200), (200, 100)], dtype=np.int32)]
cv2.drawContours(mask, pts1, -1, 2.5, 10)
mask = mask.astype(np.uint8)
cv2.findContours(mask, ,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
잘 해결되었다!
728x90