TypeError:函数正好接受4个参数(给定2个)



我目前正在处理opencv-模糊俄罗斯车辆牌照,但每次运行代码时都会出现此错误

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,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,(x,y),(x+w,y+h),(255,0,0),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,y,w,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

这通常是因为cv2.rectangle(plates,(x,y),(x+w,y+h),(255,0,0),7.5)的坐标(x,y)中存在非int值

解决方案是:

x = int(x) 
y = int(y)
w = int(w)
h = int(h)

最新更新