Ошибка после добавления строк для увеличения контрастности появилась ошибка, есть ли способ увеличить контрастность и чтобы код работал с hsv (с цветным изображением)?
import cv2 as cv2
import numpy as np
import skimage
import imutils
from imutils import contours
from skimage import measure
import argparse
import array
image = cv2.imread('1.jpeg',0)
cv2.imshow("tests", image)
cv2.waitKey()
theta = 1
phi = 1
maxIntensity = 255.0
# Decrease intensity such that
# dark pixels become much darker,
# bright pixels become slightly dark
newImage1 = (maxIntensity/phi)*(image/(maxIntensity/theta))**2
newImage1 = np.array(newImage1, dtype=np.uint8)
cv2.imshow("tests", newImage1)
cv2.waitKey()
blur = cv2.GaussianBlur(newImage1, (7,7), 0)
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (0,0,0), (179,50,55))
cv2.imshow("tests", mask)
#cv2.waitKey()
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7,7))
opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations=1)
cv2.imshow("tests", opening)
cv2.waitKey()
close = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel, iterations=2)
cv2.imshow("tests", close)
cv2.waitKey()
cnts,_ = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
approx = cv2.approxPolyDP(c, 0.04 * cv2.arcLength(c, True), True)
area = cv2.contourArea(c)
if len(approx) > 3 and area > 200:
cv2.drawContours(image, [c], -1, (0,255,0), -1)
cv2.imshow('image', image)
if cv2.waitKey(0):
cv2.destroyAllWindows()
Ошибка:
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
cv2.error: OpenCV(4.5.3) c:\users\runneradmin\appdata\local\temp\pip-req-build-sn_xpupm\opencv\modules\imgproc\src\color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function '__cdecl cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0x2f9e5da8::Set<3,-1,-1>,struct cv::impl::A0x2f9e5da8::Set<0,5,-1>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Invalid number of channels in input image:
> 'VScn::contains(scn)'
> where
> 'scn' is 1
Большое спасибо за оказанную помощь участникам форума :D !