Torsten Simon há 2 anos atrás
pai
commit
5513582cbf
1 ficheiros alterados com 10 adições e 14 exclusões
  1. 10 14
      src/data-writer.py

+ 10 - 14
src/data-writer.py

@@ -15,6 +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
     camera = None
     def __init__(self, test = False):
         self.test = test
@@ -38,16 +39,15 @@ class SolarMonitor:
             if results[0] < 80 and results[1] < 900:
                 return results
         return None
-    def thresholding(self, image):
-        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
-        
+    def getMasked(self, image):        
         pixel_values = image.reshape((-1, 1))
         pixel_values = np.float32(pixel_values)
-        print(pixel_values.shape)
+        _, result = cv2.threshold(image,self.BRIGHTNESS_THRESHOLD,255,cv2.THRESH_BINARY)
+        return result
         # define stopping criteria
         criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.2)
         # number of clusters (K)
-        k = 3
+        k = 2
         _, labels, (centers) = cv2.kmeans(pixel_values, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
         # convert back to 8 bit values
         centers = np.uint8(centers)
@@ -70,26 +70,22 @@ class SolarMonitor:
         
         return masked_image
     
-        
-        image = cv2.medianBlur(image,3)
-        #image = np.invert(image)
-        return cv2.threshold(image, 140, 255, cv2.THRESH_BINARY)[1]
-        return image
     def thresholding2(self, image):
         image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
         # Taking a matrix of size 5 as the kernel
-        kernel = np.ones((3, 3), np.uint8)
+        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
         # 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.convertScaleAbs(image, alpha=10.0, beta=-700)
         #image = cv2.erode(image, kernel, iterations=1)
-        #image = cv2.convertScaleAbs(image, alpha=2.0, beta=-50)
+        #image = cv2.convertScaleAbs(image, alpha=2.0, beta=-50)        
         #image = (255 - image)
+        image = self.getMasked(image)
+        image = cv2.dilate(image, kernel, iterations=1)
         image = cv2.medianBlur(image,3)
         #image = np.invert(image)
         return image