일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- aiffel exploration
- 오블완
- 백신후원
- AIFFEL
- docker attach
- airflow
- 기초확률론
- 히비스서커스
- numpy
- HookNet
- 코크리
- logistic regression
- 도커
- Decision Boundary
- IVI
- Multi-Resolution Networks for Semantic Segmentation in Whole Slide Images
- Pull Request
- vscode
- WSSS
- 사회조사분석사2급
- docker exec
- ssh
- docker
- GIT
- 티스토리챌린지
- Jupyter notebook
- CellPin
- cocre
- 프로그래머스
- cs231n
Archives
- Today
- Total
히비스서커스의 블로그
[OpenCV] error: OpenCV(4.5.4) /tmp/pip-req-build-sokf1_ny/opencv/modules/imgproc/src/resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function 'resize' 본문
Programming/Python
[OpenCV] error: OpenCV(4.5.4) /tmp/pip-req-build-sokf1_ny/opencv/modules/imgproc/src/resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function 'resize'
HibisCircus 2021. 12. 20. 19:00728x90
상황
np.argmax함수를 쓴 후 cv2.resize 해주려던 찰나 다음과 같은 에러 메세지를 마주하였다.
대략적인 코드
import numpy as np
import cv2
# np.argmax를 위한 과정
arg_max = np.zeros((512,512,3))
arg_max[...,1] = np.where(mask==1,1,0)
arg_max[...,2] = np.where(mask==2,1,0)
arg_max[...,0] = np.ones((512,512)) - arg_max[...,1] - arg_max[...,2]
arg_max = np.argmax(arg_max, axis=2)
# cv2.resize를 위한 과정
arg_max_resized = cv2.resize(arg_max, (128,128))
에러 메세지
error: OpenCV(4.5.4) /tmp/pip-req-build-sokf1_ny/opencv/modules/imgproc/src/resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function 'resize'
원인
argmax 과정을 거치며 data type의 변형이 이루어졌기 때문이다. cv2.resize를 할 수 있는 적정한 data type인 np.uint8로변형해주어야 한다.
해결방법
argmax 해준 변수 뒤에 .astype(np.uint8)을 붙여주면 된다.
수정된 코드
import numpy as np
import cv2
# np.argmax를 위한 과정
arg_max = np.zeros((512,512,3))
arg_max[...,1] = np.where(mask==1,1,0)
arg_max[...,2] = np.where(mask==2,1,0)
arg_max[...,0] = np.ones((512,512)) - arg_max[...,1] - arg_max[...,2]
arg_max = np.argmax(arg_max, axis=2).astype(np.uint8)
# cv2.resize를 위한 과정
arg_max_resized = cv2.resize(arg_max, (128,128))
잘 해결되었다.
-히비스서커스-
728x90