• 大小: 4KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: Python
  • 标签: opencv  

资源简介

自己弄得小程序,提取字符,省事省心,没了,为啥不能免费

资源截图

代码片段和文件信息

import numpy as np
import cv2.cv2 as cv
from matplotlib import pyplot as plt
import os
import heapq

# deal the image with binaryzation
def thresh_binary(img):
    gray = cv.cvtColor(imgcv.COLOR_BGR2GRAY)
    blur = cv.GaussianBlur(gray (9 9) 0)
    # OTSU‘s binaryzation
    (ret3 th3) = cv.threshold(blur100 255 cv.THRESH_OTSU)
    kernel = np.ones((2 2) np.uint8)
    opening = cv.morphologyEx(th3 cv.MORPH_OPEN kernel)

    #看看有几个非零像素
    # cl = opening.shape
    # feiling = cv.countNonZero(opening)
    cv.namedWindow(“Image“0)
    cv.imshow(“Image“ opening)
    return opening

# sum the black pixel numbers in each cols
def hist_col(img):
    list=[]
    row col = img.shape
    for i in xrange(col):
        list.append((img[: i] < 200).sum())
    return list

def cut_col(imgl):
    minlist = []
    np_list = np.array(l)
    a = max(l)
    row col = img.shape
    avg = col/8
    if(cv.countNonZero(img) < col*row/2): #黑底子白字
        i = 20
        while i < col - 1:
            if i >= col - 10:
                if np_list[i] > a - 10 and np_list[i] >= np_list[i+1:col].max():
                    minlist.append(i)
                    break
                if i == col - 1:
                    minlist.append(i)
                    break
            else:
                if np_list[i]>a - 20 and np_list[i] >= np_list[i:i+10].max():
                    minlist.append(i)
                    i += avg
            i += 1
        return minlistrow
    else:
        pass


#切竖着的图并接着处理
def cut_img(imgminlistrow):
    colpics = []
    for j in xrange(len(minlist)-1):
        cv.namedWindow(str(j)0)
        cv.imshow(str(j) img[0:row minlist[j]+10:minlist[j+1]+10])
     

评论

共有 条评论