如何解决类型错误:函数正好需要 4 个参数给出 2 个
我目前正在使用 opencv - 模糊俄罗斯车辆车牌,但每次运行代码时我都会得到这个 error
Traceback (most recent call last):
File "C:/Users/rohit/Desktop/test.py",line 29,in <module>
result = detect_plate(img)
File "C:/Users/rohit/Desktop/test.py",line 26,in detect_plate
cv2.rectangle(plates,(x,y),(x+w,y+h),(255,0),7.5)
TypeError: function takes exactly 4 arguments (2 given)
这是什么问题? 我确实正确加载了所有图像和 xml 文件
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('car_plate.jpg')
def display(img):
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
fig = plt.figure(figsize = (12,10))
ax = fig.add_subplot(111)
ax.imshow(img)
display(img)
plate_cascade = cv2.CascadeClassifier('haarcascade_russian_plate_number.xml')
def detect_plate(img):
plates = img.copy()
plate_rect = plate_cascade.detectMultiScale(plates)
for (x,y,w,h) in plate_rect:
cv2.rectangle(plates,7.5)
return plates
result = detect_plate(img)
display(result)
def detect_and_blur_plate(img):
plate_copy = img.copy()
plate_rect = plate_cascade.detectMultiScale(plate_copy)
for (x,h) in plate_rect:
plate_img = plate_copy[y:y+h,x:x+w]
plate_img = cv2.medianBlur(plate_img,8)
plate_copy[y:y+h,x:x+w] = plate_img
return plate_copy
result = detect_and_blur_plate(img)
display(result)
请帮助我我是初学者
解决方法
OpenCV git 板上有一个未解决的问题。您可以在此处查看:https://github.com/opencv/opencv/issues/15465
,这通常是因为 (x,y)
的坐标 cv2.rectangle(plates,(x,y),(x+w,y+h),(255,0),7.5)
中的非整数值
解决方案是:
x = int(x)
y = int(y)
w = int(w)
h = int(h)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。