Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error getting for src type CV_8UC3 to CV_8UC1 in OpenCV Python? [duplicate]

Tags:

python

opencv

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)

I get the error:

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
like image 510
Shashiwadana Avatar asked Oct 19 '20 05:10

Shashiwadana


1 Answers

img = cv.imread('t2.jpg', cv.IMREAD_GRAYSCALE)

or

img = cv.imread('t2.jpg', cv.IMREAD_COLOR)
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
like image 169
Burak Avatar answered Oct 10 '22 10:10

Burak