前言
别骂了别骂了,太久没打python,手贼生,最近在搞opencv和一些ocr,报了一堆错,有些是python的原生错误,有的是opencv的,有的是我nt,就全部记录一下吧
(1)bad argument type for built-in operation
(2)cv2.waitKey(0)在其他操作之前
会使整个操作一直维持在waitKey
(3)
cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\morph.cpp:787: error: (-215:Assertion failed) _kernel.type() == CV_8U in function 'cv::MorphFilter,struct cv::MorphIVec >::MorphFilter'
下面这两个错都是我提取数字上出的问题,第一层是一个列表第二层是字典
列表是按照排列 顺序进行查找,字典是按照 key(val)找val(key)
(4)AttributeError: ‘int’ object has no attribute ‘text’
(5)TypeError: ‘int’ object is not subscriptable
(4)和(5)我出错都是因为数据类型出问题
(6)字典类型不能去除空格
使用的代码
for i in range(0, len(result)):
result[i]['text'].replace(" ","")
print(result[i]['text'])
输出结果:
因为没有将结果传出来因此实际上调用的还是原先字典里面的,没能实现字典的val类型的去除空格
改成这样就ok了
a=result[i]['text'].replace(" ","")
print(a)
下面这两种方法好像也不行!!!
(7)local variable ‘devicecode’ referenced before assignment
当有多个输出时,一定要保证每个输出都有值
return [devicecode, boxcode, checkcode, sizecode]
我最后的解决办法挺c语言的就是说:
if flag1==0:
print("can't find devicecode")
devicecode=None
if flag2 == 0:
print("can't find boxcode")
boxcode=None
if flag3 ==0:
print("can't find checkcode")
checkcode=None
if flag4 == 0:
print("can't find sizecode")
sizecode = None
return [devicecode, boxcode, checkcode, sizecode]
could not find a writer for the specified extension in function ‘cv::imwrite_’
没写扩展名!!!
ImportError: Bindings generation error. Submodule name should always start with a parent module name. Parent name: cv2.cv2. Submodule name: cv2
改成
import cv2
– merge() takes at most 2 arguments (3 given)
image=cv2.merge(h,s,v)
image=cv2.merge([h,s,v])
Original: https://blog.csdn.net/weixin_50862344/article/details/126219700
Author: weixin_50862344
Title: 最近opencv又报了啥错(一)
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/795026/
转载文章受原作者版权保护。转载请注明原作者出处!