Skip to content
New issue

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

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

Already on GitHub? # to your account

update #15

Merged
merged 18 commits into from
Apr 17, 2019
Merged
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
storeDigitData/
.DS_Store
test.py
algorithm/OCR/newNet/images/
testImages
IMAGES

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
7 changes: 2 additions & 5 deletions algorithm/Blenometer.py → Algorithm/Blenometer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import functools
from algorithm.debug import *
import numpy as np

from algorithm.Common import *
from algorithm.debug import *
from Algorithm.utils.Finder import *
from configuration import *


def cmp(contour1, contour2):
Expand Down Expand Up @@ -71,7 +69,6 @@ def checkBleno(image, info):
return res



def readBlenometerStatus(image, info):
print("Blenometer Reader called!!!")
if image is None:
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from algorithm.OCR.newNet.dataLoader import *
from algorithm.OCR.newNet.LeNet import *
from Algorithm.OCR.newNet.dataLoader import *
from Algorithm.OCR.newNet.LeNet import *

import sys
sys.path.append("../LeNet")
Expand Down
2 changes: 1 addition & 1 deletion algorithm/OCR/test_ocr.py → Algorithm/OCR/test_ocr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cv2
from algorithm.OCR.utils import *
from Algorithm.OCR.utils import *

net = newNet()

Expand Down
10 changes: 5 additions & 5 deletions algorithm/OCR/utils.py → Algorithm/OCR/utils.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys

import cv2
import os
import numpy as np
import torch

from algorithm.debug import *
from configuration import *

sys.path.append(".")

Expand All @@ -31,11 +31,11 @@ def __init__(self):
:return:
"""
sys.path.append("newNet")
from algorithm.OCR.newNet.LeNet import myNet
from Algorithm.OCR.newNet.LeNet import myNet

self.net = myNet()
self.net.eval()
self.net.load_state_dict(torch.load("algorithm/OCR/newNet/net.pkl"))
self.net.load_state_dict(torch.load("Algorithm/OCR/newNet/net.pkl"))

def recognizeNet(self, image):
"""
Expand All @@ -52,7 +52,7 @@ def recognizeNet(self, image):
num = int(np.array(predicted[0]).astype(np.uint32))

if ifShow:
print(num)
print("this number is: ", num)
cv2.imshow("single", image)
cv2.waitKey(0)

Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions algorithm/SF6.py → Algorithm/SF6.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from algorithm.Common import *
from algorithm.debug import *
from Algorithm.utils.Finder import *
from Algorithm.utils.AngleFactory import AngleFactory
from configuration import *


def SF6Reader(image, info):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions algorithm/absorb.py → Algorithm/absorb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import numpy as np

import cv2
from algorithm.Common import AngleFactory, meterFinderByTemplate
import numpy as np


# type transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
@author: maoyingxue
"""

import json

from algorithm.debug import *
from algorithm.Common import *
from algorithm.pressure.normalPressure import normalPressure
from Algorithm.utils.Finder import *


def countArrester(image, info):
Expand Down Expand Up @@ -63,7 +59,7 @@ def countArrester(image, info):
cv2.imshow("test", image)
cv2.waitKey(0)

#value = calAngleBetweenTwoVector(np.array(startPoint)-centerPoint,pointerPoint-centerPoint)
# value = calAngleBetweenTwoVector(np.array(startPoint)-centerPoint,pointerPoint-centerPoint)
if len(pointerPoint) == 0:
return "pointer not found!"
value = calAngleClockwise(np.array(startPoint), pointerPoint, centerPoint)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import numpy as np
"""
@author: Xuyuanyuan
"""

import cv2
import numpy as np

from algorithm.debug import *
from algorithm.Common import scanPointer, meterFinderByTemplate
from Algorithm.utils.Finder import meterFinderByTemplate
from Algorithm.utils.ScanPointer import scanPointer
from configuration import *


def doubleArrester(image, info):
Expand Down
8 changes: 6 additions & 2 deletions algorithm/oilTempreture.py → Algorithm/oilTempreture.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from algorithm.Common import *
from algorithm.debug import *
import cv2
import numpy as np

from Algorithm.utils.Finder import meterFinderBySIFT
from Algorithm.utils.AngleFactory import AngleFactory
from configuration import *

red_range = [np.array([156, 120, 80]), np.array([179, 240, 220])]
white_range = [np.array([0, 0, 200]), np.array([180, 30, 255])]
Expand Down
Binary file added Algorithm/onoff/frozen_east_text_detection.pb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from algorithm.Common import meterFinderBySIFT
from algorithm.debug import *

import cv2
import numpy as np

from Algorithm.utils.Finder import meterFinderBySIFT
from configuration import *


def onoffBatteryHardCode(image, info):
"""
Expand Down
92 changes: 48 additions & 44 deletions algorithm/onoff/onoffIndoor.py → Algorithm/onoff/onoffIndoor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import math
import numpy as np
import cv2
from algorithm.debug import *
from algorithm.Common import AngleFactory, meterFinderByTemplate
from algorithm.Common import *
import json
import cv2
import numpy as np

from Algorithm.utils.Finder import meterLocationFinderBySIFT


def HSV(img):
"""
Expand All @@ -19,6 +18,7 @@ def HSV(img):

return H, S, V, h, s, v


def getBinary(img):
"""
对图像进行轮廓检测,获取图像的二值图
Expand All @@ -27,6 +27,7 @@ def getBinary(img):
edges = cv2.Canny(gray, 100, 200, apertureSize=3)
return edges


def searchUpBlack(raw, img, x, y):
"""
:param raw: 原图
Expand Down Expand Up @@ -57,6 +58,7 @@ def searchUpBlack(raw, img, x, y):
# cv2.imwrite("ww.jpg",raw)
return y, a, y, b


def searchRightRed(raw, img, x, y):
"""
:param raw: 原图
Expand Down Expand Up @@ -87,19 +89,20 @@ def searchRightRed(raw, img, x, y):

return y, a, y, b


# 裁剪目标区域值
def cutTarget(img, x1, y1, x2, y2, status):

if status=="left":
if status == "left":
len = y1 - y2
start_x = x1 - len
start_y = y1 - len
elif status=="right":
elif status == "right":
len = y1 - y2
len = len+15
len = len + 15
start_x = x1
start_y = y1 - len
return img[start_y:start_y + len, start_x:start_x + int(1.4*len)]
return img[start_y:start_y + len, start_x:start_x + int(1.4 * len)]


# 在H空间里统计某一种颜色出现的比率
def countTarPer(h_vec, which):
Expand All @@ -115,19 +118,20 @@ def countTarPer(h_vec, which):

return n, float(n / N)

#type transform
def getMatInt(Mat):

# type transform
def getMatInt(Mat):
d = Mat.shape
for i in range(d[2]):
for n in range(d[0]):
for m in range(d[1]):
Mat[n,m,i] = int(Mat[n,m,i])
Mat[n, m, i] = int(Mat[n, m, i])
# print(Mat[n,m,i])
Mat = Mat.astype(np.uint8)
return Mat

def gamma(image,thre):

def gamma(image, thre):
"""
:param image: numpy type
:param thre: float
Expand All @@ -140,42 +144,43 @@ def gamma(image,thre):
out = getMatInt(out * 255)
return out

def calDis(img,t):

def calDis(img, t):
t = int(t)
# print(t)
s1=0
s2=0
h,w = img.shape

for i in range(w):
if img[t][i]==255:
if s1==0:
s1=i
elif s2==0:
s2=i
return abs(s2-s1)
s1 = 0
s2 = 0
h, w = img.shape

for i in range(w):
if img[t][i] == 255:
if s1 == 0:
s1 = i
elif s2 == 0:
s2 = i
return abs(s2 - s1)


def judgeStatus(img):
h,w = img.shape
mid = h/2
h, w = img.shape
mid = h / 2

#画三条线
# 画三条线
t1 = mid
t2 = mid+3
t3=t2+6
#计算距离
n=0
t2 = mid + 3
t3 = t2 + 6
# 计算距离
n = 0
ts = [t1, t2, t3]

for t in ts:
if calDis(img,t)<4:
n=n+1
if calDis(img, t) < 4:
n = n + 1

# print(n)
return n



def onoffIndoor(image, info):
"""
:param image:whole image
Expand All @@ -184,12 +189,12 @@ def onoffIndoor(image, info):
"""
binary = getBinary(image)
X, Y, _, _ = meterLocationFinderBySIFT(image, info['template'])
if info['name']=="onoffIndoor1_1":
if info['name'] == "onoffIndoor1_1":
x1, y1, x2, y2 = searchUpBlack(image, binary, Y, X)
img = cutTarget(image, x1, y1, x2, y2,"left")
img = cutTarget(image, x1, y1, x2, y2, "left")
H, _, _, h, _, _ = HSV(img)
n,per = countTarPer(h, "black")
status="p"
n, per = countTarPer(h, "black")
status = "p"
if per > 0.5:
status = "close"
res = {
Expand All @@ -198,10 +203,10 @@ def onoffIndoor(image, info):
'per': per
}

elif info['name']=="onoffIndoor3_1":
elif info['name'] == "onoffIndoor3_1":
x1, y1, x2, y2 = searchRightRed(image, binary, Y, X)
img = cutTarget(image, x1, y1, x2, y2, "right")
#获取目标区域
# 获取目标区域
img = gamma(img, 0.2)
# cv2.imwrite("res.jpg", img)
img = getBinary(img)
Expand All @@ -213,7 +218,6 @@ def onoffIndoor(image, info):
'status': status
}


res = json.dumps(res)

return res
File renamed without changes.
Loading