如何使用skimage在python中对img进行模糊处理?

问题描述

我正在尝试使用python和opnecv进行车牌识别,但是返回的图像有时模糊且难以阅读,我正在使用skimage尝试对其进行模糊处理,但只是获得了白色背景而没有图像可以有人请解释如何使图像模糊化?裁剪后的变量应该是提取的img牌照,而img是原始汽车图像。谢谢

      import matplotlib.pyplot as plt
    import cv2
    import imutils
    import numpy as np
    from skimage import color,data,restoration
    from scipy.signal import convolve2d
    import pytesseract
    pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
    
    img = cv2.imread('hqdefault.jpg',cv2.IMREAD_COLOR)
    img = cv2.resize(img,(600,400) )
    
    
    
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    gray = cv2.bilateralFilter(gray,13,15,15)
    
    edged = cv2.Canny(gray,30,200)
    contours = cv2.findContours(edged.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    contours = imutils.grab_contours(contours)
    contours = sorted(contours,key = cv2.contourArea,reverse = True)[:10]
    screenCnt = None
    
    
    
    for c in contours:
    
        peri = cv2.arcLength(c,True)
        approx = cv2.approxPolyDP(c,0.018 * peri,True)
    
        if len(approx) == 4:
            screenCnt = approx
            break
    
    if screenCnt is None:
        detected = 0
        print ("No contour detected")
    else:
         detected = 1
    
    if detected == 1:
        cv2.drawContours(img,[screenCnt],-1,(0,255),3)
    
    mask = np.zeros(gray.shape,np.uint8)
    new_image = cv2.drawContours(mask,255,)
    new_image = cv2.bitwise_and(img,img,mask=mask)
    
    (x,y) = np.where(mask == 255)
    (topx,topy) = (np.min(x),np.min(y))
    (bottomx,bottomy) = (np.max(x),np.max(y))
    Cropped = gray[topx:bottomx+1,topy:bottomy+1]
    
    text = pytesseract.image_to_string(Cropped,config='--psm 11')
    print("programming_fever's License Plate Recognition\n")
    print("Detected license plate Number is:",text)
    img = cv2.resize(img,(500,300))
    Cropped = cv2.resize(Cropped,(400,200))
   // trying to use skimage
    psf = np.ones((5,5)) / 25
    Cropped  = convolve2d(Cropped,psf,'same')
    Cropped  += 0.1 * Cropped .std() * np.random.standard_normal(Cropped .shape)
    deconvolved_img = restoration.wiener(Cropped,1100)
    cv2.imshow('car',img)
    cv2.imshow('Cropped',deconvolved_img)
    // returns white background with no image?
    
    cv2.waitKey(0)
    cv2.destroyAllWindows()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...