Browse Source

improve ocr + perf

Torsten Simon 2 năm trước cách đây
mục cha
commit
09f830deab
2 tập tin đã thay đổi với 13 bổ sung10 xóa
  1. 2 0
      docker-compose.yml
  2. 11 10
      src/data-writer.py

+ 2 - 0
docker-compose.yml

@@ -45,6 +45,8 @@ services:
       DOCKER_INFLUXDB_INIT_BUCKET: influxdb
       DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: influxdbTSGAMES
       DOCKER_INFLUXDB_INIT_RETENTION: 2y
+      INFLUXD_REPORTING_DISABLED: true
+      INFLUXD_STORAGE_CACHE_MAX_MEMORY_SIZE: 50000000
     volumes:
       # Data persistency
       # sudo mkdir -p /srv/docker/influxdb/data

+ 11 - 10
src/data-writer.py

@@ -25,7 +25,7 @@ class SolarMonitor:
         custom_oem=r'--oem 3 --psm 7'
         # 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', output_type=Output.DICT)
+        #data = pytesseract.image_to_data(img, lang='letsgodigital', config=custom_oem, output_type=Output.DICT)
         print(data)
         results = []
         for i in range(len(data['text'])):
@@ -35,7 +35,7 @@ class SolarMonitor:
                 results.append(text)
         if len(results) == 2:
             results = list(map(lambda x: int(x) / 10.,results ))
-            if results[0] < 100 and results[1] < 1000:
+            if results[0] < 80 and results[1] < 900:
                 return results
         return None
     def thresholding(self, image):
@@ -85,10 +85,11 @@ class SolarMonitor:
         # convolved and third parameter is the number
         # of iterations, which will determine how much
         # you want to erode/dilate a given image.
+        image = cv2.convertScaleAbs(image, alpha=10.0, beta=-500)
         #image = cv2.dilate(image, kernel, iterations=1)
         #image = cv2.erode(image, kernel, iterations=1)
-        image = cv2.convertScaleAbs(image, alpha=2.5, beta=-210)
-        image = (255 - image)
+        #image = cv2.convertScaleAbs(image, alpha=2.0, beta=-50)
+        #image = (255 - image)
         image = cv2.medianBlur(image,3)
         #image = np.invert(image)
         return image
@@ -99,10 +100,10 @@ class SolarMonitor:
         #height= 60
         #width=230
         #return image[top : (top + height) , left: (left + width)]
-        pt_A = [225, 394]
-        pt_B = [225, 432]
-        pt_C = [419, 426]
-        pt_D = [420, 388]
+        pt_A = [225, 393]
+        pt_B = [223, 432]
+        pt_C = [420, 426]
+        pt_D = [422, 387]
         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))
@@ -127,7 +128,7 @@ class SolarMonitor:
         )
         self.camera.awb_mode = 'off'
         self.camera.awb_gains = (1.5, 2.0)
-        self.camera.shutter_speed = 50000
+        self.camera.shutter_speed = 10000
         self.camera.iso = 800
         self.camera.rotation = 180
 
@@ -181,7 +182,7 @@ class SolarMonitor:
             print(results)
             if results:
                 self.writeData(results)
-                img = cv2.putText(img, str(results), (75, 22), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (0), 1, cv2.LINE_AA)
+                img = cv2.putText(img, str(results), (75, 22), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (255), 1, cv2.LINE_AA)
             cv2.imwrite(file + '_r.jpg', img, [cv2.IMWRITE_JPEG_QUALITY, 35])
             time.sleep(5)