資源簡介
基于深度學習的文本檢測,不是文本識別!
https://blog.csdn.net/LuohenYJ
代碼片段和文件信息
#?Import?required?modules
import?cv2?as?cv
import?math
import?argparse
parser?=?argparse.ArgumentParser(description=‘Use?this?script?to?run?text?detection?deep?learning?networks?using?OpenCV.‘)
#?Input?argument
parser.add_argument(‘--input‘?help=‘Path?to?input?image?or?video?file.?Skip?this?argument?to?capture?frames?from?a?camera.‘)
#?Model?argument
parser.add_argument(‘--model‘?default=“./model/frozen_east_text_detection.pb“
????????????????????help=‘Path?to?a?binary?.pb?file?of?model?contains?trained?weights.‘
????????????????????)
#?Width?argument
parser.add_argument(‘--width‘?type=int?default=320
????????????????????help=‘Preprocess?input?image?by?resizing?to?a?specific?width.?It?should?be?multiple?by?32.‘
???????????????????)
#?Height?argument
parser.add_argument(‘--height‘type=int?default=320
????????????????????help=‘Preprocess?input?image?by?resizing?to?a?specific?height.?It?should?be?multiple?by?32.‘
???????????????????)
#?Confidence?threshold
parser.add_argument(‘--thr‘type=float?default=0.5
????????????????????help=‘Confidence?threshold.‘
???????????????????)
#?Non-maximum?suppression?threshold
parser.add_argument(‘--nms‘type=float?default=0.4
????????????????????help=‘Non-maximum?suppression?threshold.‘
???????????????????)
args?=?parser.parse_args()
############?Utility?functions?############
def?decode(scores?geometry?scoreThresh):
????detections?=?[]
????confidences?=?[]
????############?CHECK?DIMENSIONS?AND?SHAPES?OF?geometry?AND?scores?############
????assert?len(scores.shape)?==?4?“Incorrect?dimensions?of?scores“
????assert?len(geometry.shape)?==?4?“Incorrect?dimensions?of?geometry“
????assert?scores.shape[0]?==?1?“Invalid?dimensions?of?scores“
????assert?geometry.shape[0]?==?1?“Invalid?dimensions?of?geometry“
????assert?scores.shape[1]?==?1?“Invalid?dimensions?of?scores“
????assert?geometry.shape[1]?==?5?“Invalid?dimensions?of?geometry“
????assert?scores.shape[2]?==?geometry.shape[2]?“Invalid?dimensions?of?scores?and?geometry“
????assert?scores.shape[3]?==?geometry.shape[3]?“Invalid?dimensions?of?scores?and?geometry“
????height?=?scores.shape[2]
????width?=?scores.shape[3]
????for?y?in?range(0?height):
????????#?Extract?data?from?scores
????????scoresData?=?scores[0][0][y]
????????x0_data?=?geometry[0][0][y]
????????x1_data?=?geometry[0][1][y]
????????x2_data?=?geometry[0][2][y]
????????x3_data?=?geometry[0][3][y]
????????anglesData?=?geometry[0][4][y]
????????for?x?in?range(0?width):
????????????score?=?scoresData[x]
????????????#?If?score?is?lower?than?threshold?score?move?to?next?x
????????????if(score?????????????????continue
????????????#?Calculate?offset
????????????offsetX?=?x?*?4.0
????????????offsetY?=?y?*?4.0
????????????angle?=?anglesData[x]
????????????#?Calculate?cos?and?sin?of?angle
????????????cosA?=?math.cos(angle)
????????????sinA?=?math.sin(angle)
????????????h?=?x0_data[x]?+?x2_data[x]
????????????w?=?x1_data[x]?+?x3_data[x]
????????????#?Calculate?offset
評論
共有 條評論