日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python-OpenCV-- 台式机外接摄像头EAST文本检测+OCR识别

發(fā)布時(shí)間:2025/3/13 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python-OpenCV-- 台式机外接摄像头EAST文本检测+OCR识别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、代碼和訓(xùn)練文件:https://download.csdn.net/download/GGY1102/16681984

  • 利用 OpenCV 的 EAST 文本檢測器定位圖像中的文本區(qū)域。
  • 提取每個(gè)文本 ROI,然后使用 OpenCV 和 Tesseract v4 進(jìn)行文本識(shí)別。
  • ?

二、實(shí)際測試代碼

from imutils.object_detection import non_max_suppression from PIL import Image import numpy as np import pytesseract import time import cv2from matplotlib import pyplot as plt import oscap = cv2.VideoCapture(0) cap.set(cv2.CAP_PROP_FPS, 15)def decode_predictions(scores, geometry):"""EAST 文本檢測器兩個(gè)參數(shù):scores:文本區(qū)域的概率。geometry:文本區(qū)域的邊界框位置。"""# The minimum probability of a detected text regionmin_confidence = 0.5# grab the number of rows and columns from the scores volume, then# initialize our set of bounding box rectangles and corresponding# confidence scoresnumRows, numCols = scores.shape[2:4]rects = []confidences = []# loop over the number of rowsfor y in range(0, numRows):# extract the scores (probabilities), followed by the# geometrical data used to derive potential bounding box# coordinates that surround textscoresData = scores[0, 0, y]xData0 = geometry[0, 0, y]xData1 = geometry[0, 1, y]xData2 = geometry[0, 2, y]xData3 = geometry[0, 3, y]anglesData = geometry[0, 4, y]# loop over the number of columnsfor x in range(0, numCols):# if our score does not have sufficient probability,# ignore itif scoresData[x] < min_confidence:continue# compute the offset factor as our resulting feature# maps will be 4x smaller than the input image(offsetX, offsetY) = (x * 4.0, y * 4.0)# extract the rotation angle for the prediction and# then compute the sin and cosineangle = anglesData[x]cos = np.cos(angle)sin = np.sin(angle)# use the geometry volume to derive the width and height# of the bounding boxh = xData0[x] + xData2[x]w = xData1[x] + xData3[x]# compute both the starting and ending (x, y)-coordinates# for the text prediction bounding boxendX = int(offsetX + (cos * xData1[x]) + (sin * xData2[x]))endY = int(offsetY - (sin * xData1[x]) + (cos * xData2[x]))startX = int(endX - w)startY = int(endY - h)# add the bounding box coordinates and probability score# to our respective listsrects.append((startX, startY, endX, endY))confidences.append(scoresData[x])# return a tuple of the bounding boxes and associated confidencesreturn (rects, confidences)def text_recognition(image):east_model = "frozen_east_text_detection.pb"# img_path = "images/road-sign-2-768x347.jpg"# set the new width and height and then determine the ratio in change for# both the width and height, both of them are multiples of 32newW, newH = 320, 320# The (optional) amount of padding to add to each ROI border# You can try 0.05 for 5% or 0.10 for 10% (and so on) if find OCR result is incorrectpadding = 0.0# in order to apply Tesseract v4 to OCR text we must supply# (1) a language, (2) an OEM flag of 4, indicating that the we# wish to use the LSTM neural net model for OCR, and finally# (3) an OEM value, in this case, 7 which implies that we are# treating the ROI as a single line of textconfig = ("-l eng --oem 1 --psm 7") # chi_simorig = image.copy()origH, origW = image.shape[:2]# calculate ratios that will be used to scale bounding box coordinatesrW = origW / float(newW)rH = origH / float(newH)# resize the image and grab the new image dimensionsimage = cv2.resize(image, (newW, newH))(H, W) = image.shape[:2]# define the two output layer names for the EAST detector model the first is the output probabilities# and the second can be used to derive the bounding box coordinates of textlayerNames = ["feature_fusion/Conv_7/Sigmoid", "feature_fusion/concat_3"]# load the pre-trained EAST text detectorprint("[INFO] loading EAST text detector...")net = cv2.dnn.readNet(east_model)# construct a blob from the image and then perform a forward pass of# the model to obtain the two output layer setsblob = cv2.dnn.blobFromImage(image, 1.0, (W, H),(123.68, 116.78, 103.94), swapRB=True, crop=False)start = time.time()net.setInput(blob)(scores, geometry) = net.forward(layerNames)end = time.time()# show timing information on text predictionprint("[INFO] text detection cost {:.6f} seconds".format(end - start))# decode the predictions, then apply non-maxima suppression to# suppress weak, overlapping bounding boxes(rects, confidences) = decode_predictions(scores, geometry)# NMS effectively takes the most likely text regions, eliminating other overlapping regionsboxes = non_max_suppression(np.array(rects), probs=confidences)# initialize the list of results to contain our OCR bounding boxes and textresults = []# the bounding boxes represent where the text regions are, then recognize the text.# loop over the bounding boxes and process the results, preparing the stage for actual text recognitionfor (startX, startY, endX, endY) in boxes:# scale the bounding boxes coordinates based on the respective ratiosstartX = int(startX * rW)startY = int(startY * rH)endX = int(endX * rW)endY = int(endY * rH)# in order to obtain a better OCR of the text we can potentially# add a bit of padding surrounding the bounding box -- here we# are computing the deltas in both the x and y directionsdX = int((endX - startX) * padding)dY = int((endY - startY) * padding)# apply padding to each side of the bounding box, respectivelystartX = max(0, startX - dX)startY = max(0, startY - dY)endX = min(origW, endX + (dX * 2))endY = min(origH, endY + (dY * 2))# extract the actual padded ROIroi = orig[startY:endY, startX:endX]# use Tesseract v4 to recognize a text ROI in an imagetext = pytesseract.image_to_string(roi, config=config)# add the bounding box coordinates and actual text string to the results listresults.append(((startX, startY, endX, endY), text))# sort the bounding boxes coordinates from top to bottom based on the y-coordinate of the bounding boxresults = sorted(results, key=lambda r: r[0][1])output = orig.copy()# loop over the resultsfor ((startX, startY, endX, endY), text) in results:# display the text OCR'd by Tesseractprint("OCR TEXT")print("========")print("{}\n".format(text))# strip out non-ASCII text so we can draw the text on the image using OpenCVtext = "".join([c if ord(c) < 128 else "" for c in text]).strip()# draw the text and a bounding box surrounding the text region of the input imagecv2.rectangle(output, (startX, startY), (endX, endY), (0, 0, 255), 2)cv2.putText(output, text, (startX, startY - 20),cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 3)# show the output imagecv2.imshow("Text Detection", output)while True:ret, image = cap.read()text_recognition(image)# cv2.imshow('img', image)if cv2.waitKey(10) == ord("q"):break #隨時(shí)準(zhǔn)備按q退出 cap.release() cv2.destroyAllWindows()

?

參考:https://zhuanlan.zhihu.com/p/64857243

?

?

總結(jié)

以上是生活随笔為你收集整理的Python-OpenCV-- 台式机外接摄像头EAST文本检测+OCR识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 天堂av免费在线 | 女人十八岁毛片 | 在线色导航 | 美女一级视频 | 欧美国产三级 | 激情国产一区 | 久久av喷吹av高潮av萌白 | 国产二区自拍 | 九月激情网| 欧美日韩精品在线观看 | 国产尻逼视频 | 青草视频在线观看免费 | 日韩一区二区三免费高清在线观看 | 午夜激情福利 | 午夜在线一区 | 免费av在线 | 朝鲜黄色片| 精品视频免费在线 | 国产又大又黑又粗免费视频 | 五月婷婷六月色 | 欧美××××黑人××性爽 | 女性女同性aⅴ免费观女性恋 | 亚洲av成人精品一区二区三区在线播放 | 日韩一区二区三区免费在线观看 | 欧美成人一区在线观看 | 久操国产 | 东北少妇av | 青青草原亚洲 | 人妻夜夜爽天天爽三区麻豆av网站 | 乱老熟女一区二区三区 | 亚洲第一页在线观看 | 九九热免费 | 青青操视频在线观看 | 色狠av| 麻豆一区二区三区 | 中文字幕日本人妻久久久免费 | 久久人人插 | 精品偷拍一区 | 极品videosvideo喷水 | 香蕉视频在线观看www | 前任攻略在线观看免费完整版 | 国产激情一区二区三区视频免樱桃 | 亚洲最大中文字幕 | 俄罗斯av在线 | 男人都懂的网站 | 波多野结衣视频免费观看 | 亚洲偷拍一区 | 日韩特黄一级片 | 爱情岛亚洲首页论坛小巨 | 欧美日韩精品在线视频 | 久久无码高潮喷水 | 国产在线观看免费网站 | 久久这里只有精品6 | 北条麻妃一二三区 | 欧美你懂的| 精品小视频 | 日本丰满少妇裸体自慰 | 一区二区不卡免费视频 | 九七在线视频 | a国产精品 | 成人欧美一区二区三区黑人孕妇 | 影音先锋在线中文字幕 | 亚洲经典在线观看 | 假日游船法国满天星 | 91在线精品一区二区三区 | 嫩模啪啪 | 天堂在线成人 | av最新版天堂资源在线 | 亚欧洲精品 | 91一区二区 | 韩日少妇| 麻豆视频在线 | 久久久久久五月天 | 中文字幕在线永久 | 久久av资源 | 中午字幕在线观看 | 青娱乐国产精品 | 国产一区二区不卡 | 天天cao在线| 一本久久精品一区二区 | 亚洲国产精选 | 亚洲乱码视频在线观看 | 久久精品国产99国产精品 | 国产成人精品亚洲线观看 | 男女啪啪免费网站 | 国产精品入口麻豆 | 午夜天堂视频 | 国产少女免费观看高清 | 秋霞视频在线观看 | 欧美日韩免费观看视频 | 欧洲在线视频 | 97超碰伊人| 88xx成人永久免费观看 | 看片一区二区 | 伊人免费在线 | 美女视频黄色 | 日韩精品电影一区 | 小明看国产 | 综合免费视频 |