回溯(最近一次呼叫): “文件”最终.py“,第21行,英寸 lpd=牌照探测器(图像) TypeError:“module”对象不可调用
我实际上在两个文件中运行这个程序第一个文件由这个类函数组成
from collections import namedtuple
from skimage.filters import threshold_local
from skimage import segmentation
from skimage import measure
from imutils import perspective
import numpy as np
import imutils
import cv2
LicensePlate = namedtuple("LicensePlateRegion", ["success", "plate", "thresh", "candidates"])
class LicensePlateDetector:
print("entered class")
def __init__(self, image, minPlateW=60, minPlateH=20, numChars=7, minCharW=40):
self.image = image
self.minPlateW = minPlateW
self.minPlateH = minPlateH
self.numChars = numChars
self.minCharW = minCharW
def detect(self):
lpRegions = self.detectPlates()
for lpRegion in lpRegions:
lp = self.detectCharacterCandidates(lpRegion)
if lp.success:
yield (lp, lpRegion)
def detectCharacterCandidates(self, region):
plate = perspective.four_point_transform(self.image, region)
cv2.imshow("Perspective Transform", imutils.resize(plate, width=400))
V = cv2.split(cv2.cvtColor(plate, cv2.COLOR_BGR2HSV))[2]
T = threshold_local(V, 29, offset=15, method="gaussian")
thresh = (V > T).astype("uint8") * 255
thresh = cv2.bitwise_not(thresh)
plate = imutils.resize(plate, width=400)
thresh = imutils.resize(thresh, width=400)
cv2.imshow("Thresh", thresh)
labels = measure.label(thresh, neighbors=8, background=0)
charCandidates = np.zeros(thresh.shape, dtype="uint8")
for label in np.unique(labels):
if label == 0:
continue
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
cnts = cv2.findContours(labelMask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
if len(cnts) > 0:
c = max(cnts, key=cv2.contourArea)
(boxX, boxY, boxW, boxH) = cv2.boundingRect(c)
aspectRatio = boxW / float(boxH)
solidity = cv2.contourArea(c) / float(boxW * boxH)
heightRatio = boxH / float(plate.shape[0])
keepAspectRatio = aspectRatio < 1.0
keepSolidity = solidity > 0.15
keepHeight = heightRatio > 0.4 and heightRatio < 0.95
if keepAspectRatio and keepSolidity and keepHeight:
hull = cv2.convexHull(c)
cv2.drawContours(charCandidates, [hull], -1, 255, -1)
charCandidates = segmentation.clear_border(charCandidates)
return LicensePlate(success=True, plate=plate, thresh=thresh,candidates=charCandidates)
我使用argparse的第二个文件
^{pr2}$我写了这些,然后使用cmd运行命令python最终.py-i加州1.jpg。哪里最终.py是文件名组成代码的第二部分,即argparse one,而California one是由车牌组成的图像
Python不是Java。如果你想访问一个类,你需要直接导入它,或者通过你导入的模块引用它。所以:
或者
^{pr2}${cd8>推荐的原因之一是命名文件。在
相关问题 更多 >
编程相关推荐