python 等高线地图 处理_openCV python基于边缘问题的等高线查找

这篇博客介绍了如何使用OpenCV进行车牌识别,通过图像灰度化、双边滤波、Canny边缘检测找到车牌轮廓。在处理过程中遇到并解决了`cv2.findContours`返回值不匹配的问题,但最终在`cv2.contourArea`计算轮廓面积时出现错误。
摘要由CSDN通过智能技术生成

我想查出一个车号!

3d513b9718b9987d1697584c718e0104.png

使用此代码:

import numpy as np

import imutils

import cv2

# Read the image file

image = cv2.imread('Car_Image_1.jpg')

# Resize the image - change width to 500

image = imutils.resize(image, width=500)

# Display the original image

cv2.imshow("Original Image", image)

# RGB to Gray scale conversion

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

cv2.imshow("1 - Grayscale Conversion", gray)

# Noise removal with iterative bilateral filter(removes noise while preserving edges)

gray = cv2.bilateralFilter(gray, 11, 17, 17)

cv2.imshow("2 - Bilateral Filter", gray)

# Find Edges of the grayscale image

edged = cv2.Canny(gray, 170, 200)

cv2.imshow("4 - Canny Edges", edged)

# Find contours based on Edges

(new, cnts , _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

# sort contours based on their area keeping minimum required area as '30' (anything smaller than this will not be considered)

cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:30]

# we currently have no Number plate contour

NumberPlateCnt = None

# loop over our contours to find the best possible approximate contour of number plate

count = 0

for c in cnts:

peri = cv2.arcLength(c, True)

approx = cv2.approxPolyDP(c, 0.02 * peri, True)

if len(approx) == 4: # Select the contour with 4 corners

NumberPlateCnt = approx #This is our approx Number Plate Contour

break

# Drawing the selected contour on the original image

cv2.drawContours(image, [NumberPlateCnt], -1, (0,255,0), 3)

cv2.imshow("Final Image With Number Plate Detected", image)

cv2.waitKey(0) #Wait for user input before closing the images displayed

C:\Python27\python.exe C:/Users/Crypt/PycharmProjects/MyDetector/CarPlateDetection.py

Traceback (most recent call last):

File "C:/Users/Crypt/PycharmProjects/MyDetector/CarPlateDetection.py", line 27, in

(new, cnts , _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

ValueError: need more than 2 values to unpack

Process finished with exit code 1

我更改这行代码

(new, cnts , _) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

(new, cnts) = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

C:\Python27\python.exe C:/Users/Crypt/PycharmProjects/MyDetector/CarPlateDetection.py

Traceback (most recent call last):

File "C:/Users/Crypt/PycharmProjects/MyDetector/CarPlateDetection.py", line 29, in

cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:30]

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:272: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'

用退出代码1完成进程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值