Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python cv2未将图像转换为灰度_Python 3.x_Opencv_Feature Detection_3d Reconstruction - Fatal编程技术网

Python 3.x Python cv2未将图像转换为灰度

Python 3.x Python cv2未将图像转换为灰度,python-3.x,opencv,feature-detection,3d-reconstruction,Python 3.x,Opencv,Feature Detection,3d Reconstruction,因此,我编写了一个模块来检测特定图像的特征。在没有更改图像格式、源或modeule中的任何内容的情况下,它突然向我返回以下异常: gray = np.float32(cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY)) cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-pz4stnv8\opencv\modules\imgproc\src\color.c

因此,我编写了一个模块来检测特定图像的特征。在没有更改图像格式、源或modeule中的任何内容的情况下,它突然向我返回以下异常:

gray = np.float32(cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY))
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-pz4stnv8\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
模块代码如下所示:

import sys
import cv2
import numpy as np
class Unknown_algorythm_error(Exception):
    def __init__(self):
        pass
class Corner_detector():
    def __init__(self, image, detectortype="Harris", corners=[]):
        self.corners = corners
        self.image = image
        self.detectortype = detectortype
    def update(self, image=None):
        try:
            if image.type() != None:
                self.image = image
        except:
            self.image = image
        gray = np.float32(cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY))
        if self.detectortype == "Harris":
            self.corners = cv2.cornerHarris(gray, 3, 3, 0, 1)
        elif self.detectortype == "Shi-Tomasi":
            self.corners = cv2.goodFeaturesToTrack(gray, 3, 3, 0, 1)
        else:
            raise Unknown_algoryth_error
        return self.corners
    def updateanddisplay(self):
        dst = self.update(image=self.image)
        self.image[dst>0.01*dst.max()] = [0, 0, 255]
        return self.image



这是因为没有图像可转换。即使当
image.type()==None
时,您仍然调用
cvtColor()