Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: codes change to greatly enhance the performance #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dnn/darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def sample(probs):
return len(probs)-1

def c_array(ctype, values):
arr = (ctype*len(values))()
arr[:] = values
arr = (ctype * len(values))()
values = values.astype(ctype)
memmove(arr, values.ctypes.data, values.nbytes)
return arr

class BOX(Structure):
Expand Down Expand Up @@ -115,8 +116,7 @@ class METADATA(Structure):
import numpy as np
import cv2
def array_to_image(image):
boxed_image = np.array(image)
boxed_image = np.array(cv2.split(boxed_image))
boxed_image = np.array(cv2.split(image))
c = boxed_image.shape[0]
h = boxed_image.shape[1]
w = boxed_image.shape[2]
Expand Down
7 changes: 5 additions & 2 deletions dnn/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
## add opencv dnn for relu and stride
## add ocr prob for every char
"""
from ctypes import memmove

import cv2
import os
import time
Expand Down Expand Up @@ -84,8 +86,9 @@ def predict_darknet(image):
res=predict_image(ocrNet,im)
outW = int(np.ceil(w/4)-3)
nchars = len(charactersPred)
out = [ res[i] for i in range(outW*nchars)]
out = np.array(out).reshape((nchars,outW))
out = np.zeros(outW * nchars, dtype=res._type_)
memmove(out.ctypes.data, res, out.nbytes)
out = out.reshape((nchars, outW))
out = out.transpose((1,0))
out = softmax(out)

Expand Down
9 changes: 6 additions & 3 deletions dnn/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
text detect
@author: chineseocr
"""
from ctypes import memmove

import cv2
import numpy as np
from config import textPath,anchors,GPU
Expand All @@ -26,9 +28,10 @@ def detect_box(image,scale=600,maxScale=900):
scale=16
iw = int(np.ceil(im.w/scale))
ih = int(np.ceil(im.h/scale))
h,w = image.shape[:2]
out = [ res[i] for i in range(40*ih*iw)]
out=np.array(out).reshape((1,40,ih,iw))
h,w = image.shape[:2]
out = np.zeros(40 * ih * iw, dtype=res._type_)
memmove(out.ctypes.data, res, out.nbytes)
out = out.reshape((1, 40, ih, iw))
else:
inputBlob = cv2.dnn.blobFromImage(image, scalefactor=1.0, size=(w,h),swapRB=False ,crop=False);
outputName = textNet.getUnconnectedOutLayersNames()
Expand Down
4 changes: 2 additions & 2 deletions helper/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def box_to_center(box):
xmin,ymin,xmax,ymax = box
w = xmax-xmin
h = ymax-ymin
return [round(xmin,4),round(ymin,4),round(w,4),round(h,4)]
return [xmin, ymin, w, h]

newBoxes = [ box_to_center(box) for box in boxes]
newscores = [ round(float(x),6) for x in scores]
newscores = [ float(x) for x in scores]
index = cv2.dnn.NMSBoxes(newBoxes, newscores, score_threshold=score_threshold, nms_threshold=nms_threshold)
if len(index)>0:
index = index.reshape((-1,))
Expand Down