Skip to content

Commit

Permalink
升级opencv版本到4.0.0.21,opencv调用darknet部分无识别结果
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlihaoyu committed May 27, 2019
1 parent c6efd63 commit f2cb5aa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup-cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ conda create -n chineseocr python=3.6 pip scipy numpy jupyter ipython ##运用co
source activate chineseocr
git submodule init && git submodule update
cd darknet/ && make && cd ..
pip install easydict opencv-contrib-python==3.4.2.16 Cython h5py lmdb mahotas pandas requests bs4 matplotlib lxml -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install easydict opencv-contrib-python==4.0.0.21 Cython h5py lmdb mahotas pandas requests bs4 matplotlib lxml -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install -U pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install web.py==0.40.dev0
pip install keras==2.1.5 tensorflow==1.8
Expand Down
2 changes: 1 addition & 1 deletion setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
conda create -n chineseocr python=3.6 pip scipy numpy jupyter ipython ##运用conda 创建python环境
source activate chineseocr
git submodule init && git submodule update
pip install easydict opencv-contrib-python==3.4.2.16 Cython h5py lmdb mahotas pandas requests bs4 matplotlib lxml -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install easydict opencv-contrib-python==4.0.0.21 Cython h5py lmdb mahotas pandas requests bs4 matplotlib lxml -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install -U pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install keras==2.1.5 tensorflow==1.8 tensorflow-gpu==1.8
pip install web.py==0.40.dev0
Expand Down
46 changes: 29 additions & 17 deletions text/opencv_dnn_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,36 @@
else:
angleNet = cv2.dnn.readNetFromTensorflow(AngleModelPb,AngleModelPbtxt)##dnn 文字方向检测
textNet = cv2.dnn.readNetFromDarknet(yoloCfg,yoloWeights)##文字定位

def text_detect(img):
thresh=0
h,w = img.shape[:2]

inputBlob = cv2.dnn.blobFromImage(img, scalefactor=0.00390625, size=IMGSIZE,swapRB=True ,crop=False);
textNet.setInput(inputBlob)
pred = textNet.forward()
cx = pred[:,0]*w
cy = pred[:,1]*h
xmin = cx - pred[:,2]*w/2
xmax = cx + pred[:,2]*w/2
ymin = cy - pred[:,3]*h/2
ymax = cy + pred[:,3]*h/2
scores = pred[:,4]
indx = np.where(scores>thresh)[0]
scores = scores[indx]
boxes = np.array(list(zip(xmin[indx],ymin[indx],xmax[indx],ymax[indx])))
return boxes,scores
thresh = 0
img_height,img_width = img.shape[:2]
inputBlob = cv2.dnn.blobFromImage(img, scalefactor=1.0, size=IMGSIZE,swapRB=True ,crop=False);
textNet.setInput(inputBlob/255.0)
outputName = textNet.getUnconnectedOutLayersNames()
outputs = textNet.forward(outputName)
class_ids = []
confidences = []
boxes = []
for output in outputs:
for detection in output:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > thresh:
center_x = int(detection[0] * img_width)
center_y = int(detection[1] * img_height)
width = int(detection[2] * img_width)
height = int(detection[3] * img_height)
left = int(center_x - width / 2)
top = int(center_y - height / 2)
if class_id==1:
class_ids.append(class_id)
confidences.append(float(confidence))
boxes.append([left, top,left+width, top+height ])

return np.array(boxes),np.array(confidences)



def angle_detect_dnn(img,adjust=True):
Expand Down

0 comments on commit f2cb5aa

Please sign in to comment.