GVKun编程网logo

Python cv2 ORB检测和计算返回“输入图像中的通道数无效”(python输出图像通道数)

1

本文将为您提供关于Pythoncv2ORB检测和计算返回“输入图像中的通道数无效”的详细介绍,我们还将为您解释python输出图像通道数的相关知识,同时,我们还将为您提供关于-->8_,ctrs,_=

本文将为您提供关于Python cv2 ORB检测和计算返回“输入图像中的通道数无效”的详细介绍,我们还将为您解释python输出图像通道数的相关知识,同时,我们还将为您提供关于--> 8_,ctrs,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) ValueError: 没有足够的值来解包预期 3,得到 2、AttributeError: module cv2.cv2 has no attribute create ThinPlateSplineShapeTransformer 报错、AttributeError:模块'cv2.cv2'没有属性'createLBPHFaceRecognizer'、AttributeError:模块'cv2.cv2'没有属性'xfeatures2d'[Opencv 3.4.3]的实用信息。

本文目录一览:

Python cv2 ORB检测和计算返回“输入图像中的通道数无效”(python输出图像通道数)

Python cv2 ORB检测和计算返回“输入图像中的通道数无效”(python输出图像通道数)

如何解决Python cv2 ORB检测和计算返回“输入图像中的通道数无效”

我正在尝试从两个不同的图像中提取和匹配特征,但由于某种原因,“detectAndCompute”方法不适用于我的 orb 对象: orb = cv2.ORB_create() kp,corners = orb.detectAndCompute(image,None 我正在传递单个灰度图像(函数 np.float32(cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)) 的返回)。由于某种原因,程序返回以下错误: 回溯(最近一次调用最后一次): 文件“C:\\Users\\levxr\\Desktop\\Visual-positioning-bot-main\\alloverlay.py”,第 37 行,在 cv2.imshow("相机"+str(i),corn1.updateanddisplay()) 文件“C:\\Users\\levxr\\Desktop\\Visual-positioning-bot-main\\features.py”,第 33 行,在 updateanddisplay dst = self.update(image=self.image) 文件“C:\\Users\\levxr\\Desktop\\Visual-positioning-bot-main\\features.py”,第 23 行,更新中 kp,None) cv2.error: OpenCV(4.4.0) c:\\users\\appveyor\\appdata\\local\\temp\\1\\pip-req-build-95hbg2jt\\opencv\\modules\\imgproc\\src\\color.simd_helpers.hpp:92: 错误: (-2:Unspecified error) in function ''__cdecl cv::impl::anonymous-namespace''::CvtHelper<struct cv::impl::anonymous namespace''::Set,struct cv::impl::A0x2980c61a::Set,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)''

输入图像中的通道数无效: ''VScn::包含(scn)'' 在哪里 ''scn'' 是 1

程序分为3个文件,alloverlay.py(主文件):

  1. import sys
  2. import cv2
  3. import numpy as np
  4. import features as corn
  5. import camera as cali
  6. cv2.ocl.setUSEOpenCL(False)
  7. #videoname = input("enter input")
  8. videoname = "camera10001-0200.mkv"
  9. try:
  10. videoname = int(videoname)
  11. cap = cv2.VideoCapture(videoname)
  12. except:
  13. cap = cv2.VideoCapture(videoname)
  14. videoname2 = "camera 20000-0200.mkv"
  15. try:
  16. videoname = int(videoname)
  17. cap2 = cv2.VideoCapture(videoname)
  18. except:
  19. cap2 = cv2.VideoCapture(videoname)
  20. if cap.isOpened()and cap2.isOpened():
  21. ret1,image1 = cap.read()
  22. ret2,image2 = cap2.read()
  23. ret = [ret1,ret2]
  24. image = [np.float32(cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY)),np.float32(cv2.cvtColor(image2,cv2.COLOR_BGR2GRAY))]
  25. cali1 = cali.Calibrator()
  26. corn1 = corn.Corner_detector(image)
  27. while cap.isOpened() and cap2.isOpened():
  28. ret[0],image[0] = cap.read()
  29. ret[1],image[1] = cap2.read()
  30. if ret:
  31. backupimg = image
  32. for i,img in enumerate(image):
  33. if cali1.calibrated:
  34. backupimg[i] = corn1.image = cali1.undistort(np.float32(cv2.cvtColor(image[i],cali1.mtx,cali1.dist)
  35. else:
  36. backupimg[i] = corn1.image = np.float32(cv2.cvtColor(img,cv2.COLOR_BGR2GRAY))
  37. cv2.imshow("camera "+str(i),corn1.updateanddisplay())
  38. image = backupimg
  39. print(ret,image)
  40. #cv2.imshow("test",image)
  41. key = cv2.waitKey(1)
  42. if key == ord("c"):
  43. cali1.calibrate(cali1.image)
  44. if cv2.waitKey(25) & 0xFF == ord("q"):
  45. break
  46. else:
  47. print("capture not reading")
  48. break
  49. cap.release()

,camera.py(用于校准和不失真相机并三角测量点的相对位置的模块(该项目的不同部分,与此问题无关)):

  1. import sys
  2. import cv2
  3. #import glob
  4. import numpy as np
  5. cv2.ocl.setUSEOpenCL(False)
  6. class Missing_calibration_data_error(Exception):
  7. def __init__():
  8. pass
  9. class Calibrator():
  10. def __init__(self,image=None,mtx=None,dist=None,camera_data={"pixelsize":None,"matrixsize":None,"baseline":None,"lens_distance":None},criteria=(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER,30,0.001),calibrated = False):
  11. self.criteria = criteria
  12. self.objpoints = []
  13. self.imgpoints = []
  14. self.objp = np.zeros((6*7,3),np.float32)
  15. self.objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
  16. self.image = image
  17. self.mtx = mtx
  18. self.dist = dist
  19. self.calibrated = calibrated
  20. self.pixelsize = camera_data["pixelsize"]
  21. self.matrixsize = camera_data["matrixsize"]
  22. self.baseline = camera_data["baseline"]
  23. self.lens_distance = camera_data["lens_distance"]
  24. def calibrate(self,image):
  25. gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
  26. ret,corners = cv2.findChessboardCorners(gray,(7,6),None)
  27. if ret == True:
  28. self.objpoints.append(self.objp)
  29. corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),self.criteria)
  30. self.imgpoints.append(corners2)
  31. h,w = image.shape[:2]
  32. ret,mtx,dist,rvecs,tvecs = cv2.calibrateCamera(objpoints,imgpoints,gray.shape[::-1],None,None)
  33. self.mtx = mtx
  34. self.dist = dist
  35. self.calibrated = True
  36. return mtx,dist
  37. def undistort(self,image,dist):
  38. if dist == None or mtx == None or image == None:
  39. raise Missing_calibration_data_error
  40. h,w = image.shape[:2]
  41. newcameramtx,roi=cv2.getoptimalNewCameraMatrix(mtx,(w,h),1,h))
  42. dst = cv2.undistort(image,newcameramtx)
  43. x,y,w,h = roi
  44. dst = dst[y:y+h,x:x+w]
  45. return image
  46. def calculate_point_relative_position(self,point_location2d):
  47. angle = self.baseline/(point_location2d[left][x]-point_location2d[right][x])
  48. x = angle * (point_location2d[left][x]-self.matrixsize[0]/2)
  49. y = angle * (point_location2d[left][y]-self.matrixsize[1]/2)
  50. z = self.lens_distance * (1-angle/self.pixelsize)
  51. return [x,z]
  52. ´´´,and features.py(module to detect and match the features,aparently where the issue happens):
  53. ´´´
  54. import sys
  55. import cv2
  56. import numpy as np
  57. cv2.ocl.setUSEOpenCL(False)
  58. class UnkNown_algorythm_error(Exception):
  59. def __init__(self):
  60. pass
  61. class No_image_passed_error(Exception):
  62. def __int__ (self):
  63. pass
  64. class Corner_detector():
  65. def __init__(self,detectortype="ORB",corners=[]):
  66. self.corners = corners
  67. self.image = image
  68. self.detectortype = detectortype
  69. def update(self,image=None):
  70. if self.detectortype == "Harris":
  71. self.corners = cv2.cornerHarris(image,3,1)
  72. elif self.detectortype == "Shi-Tomasi":
  73. self.corners = cv2.goodFeaturesToTrack(image,1)
  74. elif self.detectortype == "ORB":
  75. orb = cv2.ORB_create()
  76. kp,None)
  77. elif self.detectortype == "SURF":
  78. minHessian = 400
  79. detector = cv2.features2d_SURF(hessianThreshold=minHessian)
  80. keypoints1,descriptors1 = detector.detectAndCompute(img1,None)
  81. keypoints2,descriptors2 = detector.detectAndCompute(img2,None)
  82. else:
  83. raise UnkNown_algoryth_error
  84. return self.corners
  85. def updateanddisplay(self):
  86. dst = self.update(image=self.image)
  87. self.image[dst>0.01*dst.max()] = 0
  88. return self.image
  89. class Feature_matcher():
  90. def __init__(self,matcher = cv2.DescriptorMatcher_create(cv2.DescriptorMatcher_FLANNBASED)):
  91. self.matcher = matcher
  92. ´´´
  93. Does anyone kNow how to fix this? I''ve been looking for the answer for quite a while but i only find the answer for when you''re converting the image to grayscale and it doesnt work for me.

解决方法

很难理解,但我想我发现了问题:
您正在传递 orb.detectAndCompute 类型为 np.float32 的图像。

  • orb.detectAndCompute 不支持 np.float32 类型的图像。

重现问题:

以下“简单测试”重现问题:
代码示例将黑色(零)图像传递给 orb.detectAndCompute

以下代码无异常通过(图片类型为np.uint8):

  1. # image type is uint8:
  2. image = np.zeros((100,100),np.uint8)
  3. orb = cv2.ORB_create()
  4. kp,corners = orb.detectAndCompute(image,None)

以下代码引发异常,因为图像类型为 np.float32

  1. # image type is float32:
  2. image = np.float32(np.zeros((100,np.uint8))
  3. orb = cv2.ORB_create()
  4. kp,None)

引发异常:

输入图像中的通道数无效:


解决方案:

尽量避免 np.float32 转换。
您还可以将 image 转换为 uint8,如下所示:

  1. kp,corners = orb.detectAndCompute(image.astype(np.uint8),None)

--> 8_,ctrs,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) ValueError: 没有足够的值来解包预期 3,得到 2

--> 8_,ctrs,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) ValueError: 没有足够的值来解包预期 3,得到 2

如何解决--> 8_,ctrs,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) ValueError: 没有足够的值来解包预期 3,得到 2

我收到这样的错误:

  1. ---------------------------------------------------------------------------
  2. ValueError Traceback (most recent call last)
  3. <ipython-input-38-c01841a65106> in <module>
  4. 1 #assign "-"=10
  5. ----> 2 data=load_images_from_folder("D:/Handwritten-Equation-Solver-master (1)/Handwritten-Equation-Solver-master/extracted_images/-")
  6. 3 len(data)
  7. 4 for i in range(0,len(data)):
  8. 5 data[i]=np.append(data[i],["10"])
  9. <ipython-input-36-de2a2236b032> in load_images_from_folder(folder)
  10. 6 if img is not None:
  11. 7 _,thresh=cv2.threshold(img,127,255,cv2.THRESH_BINARY)
  12. ----> 8 _,ctrs,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
  13. 9 cnt=sorted(ctrs,key=lambda ctr:cv2.boundingRect(ctr)[0])
  14. 10 w=int(28)
  15. ValueError: not enough values to unpack (expected 3,got 2)

请帮我解决这个问题。

AttributeError: module cv2.cv2 has no attribute create ThinPlateSplineShapeTransformer 报错

AttributeError: module cv2.cv2 has no attribute create ThinPlateSplineShapeTransformer 报错

使用opencv-python报错:

AttributeError: module ''cv2.cv2'' has no attribute ''createThinPlateSplineShapeTransformer''

解决方法:

pip install opencv-contrib-python

AttributeError:模块'cv2.cv2'没有属性'createLBPHFaceRecognizer'

AttributeError:模块'cv2.cv2'没有属性'createLBPHFaceRecognizer'

我在运行识别代码的面部时遇到一些属性错误。 我的脸检测代码完美运行。但是,当我尝试运行脸识别代码时,它显示一些属性错误。 我GOOGLE了,并试图遵循所有的步骤。 但是,它仍然显示相同的错误。 这是我的代码:

人脸识别

我得到以下错误:

如何获取systeminfo语言环境 – Locale.getDefault()

如何确定我的.NET Windows Forms程序运行在哪个监视器上?

猴子testing软件的Windows应用程序

在Windows c ++应用程序中获取主线程的控制权

如何从LAN上的另一台PC访问瓶子开发服务器?

C:UsersMANAppDataLocalProgramsPythonpython36python.exe C:/Users/MAN/PycharmProjects/facerecognition/Recognise/recognize1.py Traceback (most recent call last): File "C:/Users/MAN/PycharmProjects/facerecognition/Recognise/recognize1.py",line 4,in <module> recognizer = cv2.createLBPHFaceRecognizer() AttributeError: module ''cv2.cv2'' has no attribute ''createLBPHFaceRecognizer'' Process finished with exit code 1.

我正在使用Windows平台。 python 3.6版本。提前感谢。

在“窗口”对话框中使用“cout”显示消息 – C ++

处理python 3.0中的文件属性

Win32窗口线程安全吗?

从c#注册一个自定义的win32窗口类

win32:如何计算控制大小,以跨Windows版本/主题一致的外观?

你需要安装opencv-contrib

pip install opencv-contrib-python

它应该在那之后工作。

opencv已经改变了一些函数,并将它们移动到它们的opencv_contrib回购,所以你必须调用所提到的方法:

recognizer = cv2.face.createLBPHFaceRecognizer()

注意:您可以看到有关丢失文档的这个问题 。 尝试使用帮助功能help(cv2.face.createLBPHFaceRecognizer)了解更多详情。

使用以下内容

recognizer = **cv2.face.LBPHFaceRecognizer_create()**

安装完成后:

pip install opencv-contrib

如果使用蟒蛇然后在蟒蛇预防:

conda install pip

然后

pip install opencv-contrib

总结

以上是小编为你收集整理的AttributeError:模块''cv2.cv2''没有属性''createLBPHFaceRecognizer''全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

AttributeError:模块'cv2.cv2'没有属性'xfeatures2d'[Opencv 3.4.3]

AttributeError:模块'cv2.cv2'没有属性'xfeatures2d'[Opencv 3.4.3]

我已经安装了opencv 3.4.3(使用pip3 install opencv-pythonpip3 install opencv-python-contrib

当我运行包含此行的代码时:
sift = cv2.xfeatures2d.SIFT_create()
我收到此错误:

AttributeError: module ''cv2.cv2'' has no attribute ''xfeatures2d''

xfeatures2d功能不再通过OpenCV的3.4.3支持?

答案1

小编典典

您收到的错误消息与该模块xfeatures2d不存在有关。它与SIFT算法没有直接关系,也与其中的任何算法都没有关系xfeatures2d(所有都会发送该错误)。我建议您要么重新安装opencv-contrib-python(pip install opencv-contrib-python),要么使用anaconda或同等工具从另一个源存储库重新安装两个opencv软件包。最后一个选择是,如果您愿意的话,可以自己编译完整的OpenCV(“常规”+ contrib)。

希望能帮助到你。

关于Python cv2 ORB检测和计算返回“输入图像中的通道数无效”python输出图像通道数的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于--> 8_,ctrs,_=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) ValueError: 没有足够的值来解包预期 3,得到 2、AttributeError: module cv2.cv2 has no attribute create ThinPlateSplineShapeTransformer 报错、AttributeError:模块'cv2.cv2'没有属性'createLBPHFaceRecognizer'、AttributeError:模块'cv2.cv2'没有属性'xfeatures2d'[Opencv 3.4.3]的相关信息,请在本站寻找。

本文标签: