Torsten Simon 2 ani în urmă
părinte
comite
168c1e0c86
1 a modificat fișierele cu 17 adăugiri și 9 ștergeri
  1. 17 9
      src/data-writer.py

+ 17 - 9
src/data-writer.py

@@ -15,7 +15,7 @@ client = InfluxDBClient(host="localhost", port=8086, username="influxdb", passwo
 client.create_database("influxdb")
 client.switch_database('influxdb')
 class SolarMonitor:
-    BRIGHTNESS_THRESHOLD = 78 # 0-255
+    BRIGHTNESS_THRESHOLD = 50 # 0-255
     camera = None
     def __init__(self, test = False):
         self.test = test
@@ -27,6 +27,7 @@ class SolarMonitor:
         # https://github.com/adrianlazaro8/Tesseract_sevenSegmentsLetsGoDigital
         data = pytesseract.image_to_data(img, lang='lets', config=custom_oem, output_type=Output.DICT)
         #data = pytesseract.image_to_data(img, lang='letsgodigital', config=custom_oem, output_type=Output.DICT)
+        #data = pytesseract.image_to_data(img, config=custom_oem, output_type=Output.DICT)
         print(data)
         results = []
         for i in range(len(data['text'])):
@@ -42,7 +43,7 @@ class SolarMonitor:
     def getMasked(self, image):        
         pixel_values = image.reshape((-1, 1))
         pixel_values = np.float32(pixel_values)
-        _, result = cv2.threshold(image,self.BRIGHTNESS_THRESHOLD,255,cv2.THRESH_BINARY)
+        _, result = cv2.threshold(image,self.BRIGHTNESS_THRESHOLD,255,cv2.THRESH_TRUNC)
         return result
         # define stopping criteria
         criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.2)
@@ -71,10 +72,9 @@ class SolarMonitor:
         return masked_image
     
     def thresholding2(self, image):
-        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
-        # Taking a matrix of size 5 as the kernel
-        kernel = np.ones((2, 2), np.uint8)
+        #image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
         
+        #kernel = np.ones((2, 2), np.uint8)
         # The first parameter is the original image,
         # kernel is the matrix with which image is
         # convolved and third parameter is the number
@@ -84,9 +84,17 @@ class SolarMonitor:
         #image = cv2.erode(image, kernel, iterations=1)
         #image = cv2.convertScaleAbs(image, alpha=2.0, beta=-50)        
         #image = (255 - image)
-        image = self.getMasked(image)
-        image = cv2.dilate(image, kernel, iterations=1)
+        # image = self.getMasked(image)
+        #image = cv2.dilate(image, kernel, iterations=1)
         image = cv2.medianBlur(image,3)
+        #thresh = cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,51,1)
+        # detect the contours on the binary image using cv2.CHAIN_APPROX_NONE
+        #contours, hierarchy = cv2.findContours(image=thresh, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
+                                            
+        #cv2.drawContours(image=image, contours=contours, contourIdx=-1, color=(255, 255, 255), thickness=1, lineType=cv2.LINE_AA)
+
+        #im2, contours = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
+        # cv2.drawContours(image, contours, -1, (0,255,0), 3)
         #image = np.invert(image)
         return image
     
@@ -96,10 +104,10 @@ class SolarMonitor:
         #height= 60
         #width=230
         #return image[top : (top + height) , left: (left + width)]
-        pt_A = [225, 393]
+        pt_A = [225, 390]
         pt_B = [223, 432]
         pt_C = [420, 426]
-        pt_D = [422, 387]
+        pt_D = [422, 384]
         width_AD = np.sqrt(((pt_A[0] - pt_D[0]) ** 2) + ((pt_A[1] - pt_D[1]) ** 2))
         width_BC = np.sqrt(((pt_B[0] - pt_C[0]) ** 2) + ((pt_B[1] - pt_C[1]) ** 2))
         maxWidth = max(int(width_AD), int(width_BC))