diff --git a/setup-cpu.md b/setup-cpu.md index 9de7191bcb69e906d6c0dcf679a66b4db5ed5959..7124ce8ff068a5849c0c15e5afb2cc3011321169 100644 --- a/setup-cpu.md +++ b/setup-cpu.md @@ -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 diff --git a/setup.md b/setup.md index fb5bdbd2aead1ebe33b381ccc3a8ed4d73f5172c..887b2be7f9ea24bb725ea0f7d8c5b244a0333996 100644 --- a/setup.md +++ b/setup.md @@ -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 diff --git a/text/opencv_dnn_detect.py b/text/opencv_dnn_detect.py index f3310c16bf2027ed954517e88ece42b1d7f94326..0a9a1446e7849e6d79ffaa3785aba2d38c133196 100644 --- a/text/opencv_dnn_detect.py +++ b/text/opencv_dnn_detect.py @@ -24,24 +24,36 @@ if opencvFlag=='keras': 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):