Opencv - Grayscale mode Vs gray color conversion
(1 个回答)
9 个月前关闭。
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('t2.jpg', cv.COLOR_BGR2GRAY)
blur = cv.GaussianBlur(img, (5, 5), 0)
ret3, th3 = cv.threshold(blur, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
我收到错误:
Traceback (most recent call last):
File "F:/l4 project docs/project/l4proTest1/projectionStepTest.py", line 11, in <module>
ret3,th3 = cv.threshold(blur, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-9d_dfo3_\opencv\modules\imgproc\src\thresh.cpp:1557: error: (-2:Unspecified error) in function 'double __cdecl cv::threshold(const class cv::_InputArray &,const class cv::_OutputArray &,double,double,int)'
THRESH_OTSU mode:
'src_type == CV_8UC1 || src_type == CV_16UC1'
where
'src_type' is 16 (CV_8UC3)
Process finished with exit code 1
img = cv.imread('t2.jpg', cv.IMREAD_GRAYSCALE)
或者
img = cv.imread('t2.jpg', cv.IMREAD_COLOR)
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
我是一名优秀的程序员,十分优秀!