提交 f2cb5aa2 编写于 作者: W wenlihaoyu

升级opencv版本到4.0.0.21,opencv调用darknet部分无识别结果

上级 c6efd637
...@@ -3,7 +3,7 @@ conda create -n chineseocr python=3.6 pip scipy numpy jupyter ipython ##运用co ...@@ -3,7 +3,7 @@ conda create -n chineseocr python=3.6 pip scipy numpy jupyter ipython ##运用co
source activate chineseocr source activate chineseocr
git submodule init && git submodule update git submodule init && git submodule update
cd darknet/ && make && cd .. 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 -U pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install web.py==0.40.dev0 pip install web.py==0.40.dev0
pip install keras==2.1.5 tensorflow==1.8 pip install keras==2.1.5 tensorflow==1.8
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
conda create -n chineseocr python=3.6 pip scipy numpy jupyter ipython ##运用conda 创建python环境 conda create -n chineseocr python=3.6 pip scipy numpy jupyter ipython ##运用conda 创建python环境
source activate chineseocr source activate chineseocr
git submodule init && git submodule update 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 -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 keras==2.1.5 tensorflow==1.8 tensorflow-gpu==1.8
pip install web.py==0.40.dev0 pip install web.py==0.40.dev0
......
...@@ -24,24 +24,36 @@ if opencvFlag=='keras': ...@@ -24,24 +24,36 @@ if opencvFlag=='keras':
else: else:
angleNet = cv2.dnn.readNetFromTensorflow(AngleModelPb,AngleModelPbtxt)##dnn 文字方向检测 angleNet = cv2.dnn.readNetFromTensorflow(AngleModelPb,AngleModelPbtxt)##dnn 文字方向检测
textNet = cv2.dnn.readNetFromDarknet(yoloCfg,yoloWeights)##文字定位 textNet = cv2.dnn.readNetFromDarknet(yoloCfg,yoloWeights)##文字定位
def text_detect(img): def text_detect(img):
thresh=0 thresh = 0
h,w = img.shape[:2] img_height,img_width = img.shape[:2]
inputBlob = cv2.dnn.blobFromImage(img, scalefactor=1.0, size=IMGSIZE,swapRB=True ,crop=False);
inputBlob = cv2.dnn.blobFromImage(img, scalefactor=0.00390625, size=IMGSIZE,swapRB=True ,crop=False); textNet.setInput(inputBlob/255.0)
textNet.setInput(inputBlob) outputName = textNet.getUnconnectedOutLayersNames()
pred = textNet.forward() outputs = textNet.forward(outputName)
cx = pred[:,0]*w class_ids = []
cy = pred[:,1]*h confidences = []
xmin = cx - pred[:,2]*w/2 boxes = []
xmax = cx + pred[:,2]*w/2 for output in outputs:
ymin = cy - pred[:,3]*h/2 for detection in output:
ymax = cy + pred[:,3]*h/2 scores = detection[5:]
scores = pred[:,4] class_id = np.argmax(scores)
indx = np.where(scores>thresh)[0] confidence = scores[class_id]
scores = scores[indx] if confidence > thresh:
boxes = np.array(list(zip(xmin[indx],ymin[indx],xmax[indx],ymax[indx]))) center_x = int(detection[0] * img_width)
return boxes,scores 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): def angle_detect_dnn(img,adjust=True):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册