【发布时间】:2021-04-02 04:25:28
【问题描述】:
我目前正在研究 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,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)
请帮助我,我是初学者
【问题讨论】:
-
错误表示该函数需要 4 个参数,而您为它提供了 2 个参数,我会尝试将表达式移出并将它们存储在单个变量中,然后将变量作为函数参数传递,这可能澄清发生了什么。
标签: python opencv face-detection cv2 cascade