我是opencv的新手,想了解更多。这是我的管道:
import cv2
import numpy
import math
from enum import Enum
class GripPipeline:
"""
An OpenCV pipeline generated by GRIP.
"""
def __init__(self):
"""initializes all values to presets or None if need to be set
"""
self.__cv_resize_dsize = (0, 0)
self.__cv_resize_fx = 0.25
self.__cv_resize_fy = 0.25
self.__cv_resize_interpolation = cv2.INTER_LINEAR
self.cv_resize_output = None
self.__hsv_threshold_input = self.cv_resize_output
self.__hsv_threshold_hue = [0.4556876738819602, 93.45444422147858]
self.__hsv_threshold_saturation = [37.56692583788217, 145.8721694981769]
self.__hsv_threshold_value = [1.7210414835158088, 187.92607745473873]
self.hsv_threshold_output = None
self.__cv_erode_src = self.hsv_threshold_output
self.__cv_erode_kernel = None
self.__cv_erode_anchor = (-1, -1)
self.__cv_erode_iterations = 1.0
self.__cv_erode_bordertype = cv2.BORDER_CONSTANT
self.__cv_erode_bordervalue = (-1)
self.cv_erode_output = None
self.__mask_input = self.cv_resize_output
self.__mask_mask = self.cv_erode_output
self.mask_output = None
self.__find_blobs_input = self.mask_output
self.__find_blobs_min_area = 16.0
self.__find_blobs_circularity = [0.0, 1.0]
self.__find_blobs_dark_blobs = False
self.find_blobs_output = None
def process(self, source0):
"""
Runs the pipeline and sets all outputs to new values.
"""
# Step CV_resize0:
self.__cv_resize_src = source0
(self.cv_resize_output) = self.__cv_resize(self.__cv_resize_src, self.__cv_resize_dsize, self.__cv_resize_fx, self.__cv_resize_fy, self.__cv_resize_interpolation)
# Step HSV_Threshold0:
/code/
# Step CV_erode0:
/code/
# Step Mask0:
/code/
# Step Find_Blobs0:
/code/
@staticmethod
def __cv_resize(src, d_size, fx, fy, interpolation):
"""Resizes an Image.
Args:
src: A numpy.ndarray.
d_size: Size to set the image.
fx: The scale factor for the x.
fy: The scale factor for the y.
interpolation: Opencv enum for the type of interpolation.
Returns:
A resized numpy.ndarray.
"""
return cv2.resize(src, d_size, fx=fx, fy=fy, interpolation=interpolation)
那里有很多“def”和我的创建对象使用我的笔记本电脑相机我确信这不是相机问题,因为我试图从中捕获 img 并且我成功了。:
My_Pipeline = GripPipeline()
My_Pipeline.process(cv2.VideoCapture(0))
它引发的错误:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
My_Pipeline.process(cv2.VideoCapture(0))
File "C:\Users\lenovo\Desktop\grip.py", line 57, in process
(self.cv_resize_output) = self.__cv_resize(self.__cv_resize_src,
self.__cv_resize_dsize, self.__cv_resize_fx, self.__cv_resize_fy,
self.__cv_resize_interpolation)
File "C:\Users\lenovo\Desktop\grip.py", line 89, in __cv_resize
return cv2.resize(src, d_size, fx=fx, fy=fy,
interpolation=interpolation)
TypeError: src is not a numpy array, neither a scalar
我是 Opencv 的新手,只想了解更多!非常感谢您查看此问题!