def start():
    serverData = SocketServer()

    EW_videoCapture = cv2.VideoCapture(paths.EW_VIDEO_PATH)
    NS_videoCapture = cv2.VideoCapture(paths.NS_VIDEO_PATH)

    bgSubtractor = cv2.createBackgroundSubtractorMOG2(varThreshold=230,
                                                      detectShadows=True)

    # frameWidth = int(videoCapture.get(3))
    # frameHeight = int(videoCapture.get(4))
    # linePoint1 = (0, int(frameHeight / 2))
    # linePoint2 = (frameWidth, int(frameHeight / 2))

    while True:

        _, EW_frame = EW_videoCapture.read()
        _, NS_frame = EW_videoCapture.read()

        # cv2.line(frame, linePoint1, linePoint2, (0, 0, 255), 2)

        EW_fgMask = bgSubtractor.apply(EW_frame)
        NS_fgMask = bgSubtractor.apply(NS_frame)

        EW_fgMask = mask_preproscessing(EW_fgMask)
        NS_fgMask = mask_preproscessing(NS_fgMask)

        EW_contours, _ = cv2.findContours(EW_fgMask, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_SIMPLE)
        NS_contours, _ = cv2.findContours(NS_fgMask, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_SIMPLE)

        serverDataStr = str(len(NS_contours)) + "+" + str(len(EW_contours))
        print(serverDataStr)
        serverData.send(serverDataStr)

        cv2.drawContours(EW_frame, EW_contours, -1, (0, 255, 0), 2)
        cv2.drawContours(NS_frame, NS_contours, -1, (0, 255, 0), 2)

        cv2.imshow("EW_Contours", EW_frame)
        cv2.imshow("NS_Contours", NS_frame)

        key = cv2.waitKey(50)
        if key == 27:
            break

    EW_videoCapture.release()
    NS_videoCapture.release()
    cv2.destroyAllWindows()
Exemplo n.º 2
0
 def __init__(self):
     SocketServer.__init__(self)
     self.BATCH_SIZE=16
     self.raw_data=Loader('..//Database//Plastics_and_Chemicals_Macro.csv')
     self.data,self._min,self._max=Normalize(self.raw_data)
     self._data=self.data[:,14:30]
     self.data=self.data[:,14:30]
     self.data=torch.Tensor(self.data)
     self.dataSize=self.data.shape[0]
     self._dataset=Data.TensorDataset(self.data,self.data)
     self.test_loader=Data.DataLoader(dataset=self._dataset,batch_size=1,shuffle=False)
     self.train_loader=Data.DataLoader(dataset=self._dataset,batch_size=self.BATCH_SIZE,shuffle=True)   
     
     self.AE=self.LoadAE()
     self.la,self.re=self.ModelEval(self.AE)
Exemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        """
        Crating a server object whit default host and port and set timeout 0.1 second.

        :param args:
        :param kwargs:
        """
        super(TestSocketServer, self).__init__(*args, **kwargs)
        self.server = SocketServer(timeout=0.1)
Exemplo n.º 4
0
class TestSocketServer(unittest.TestCase):
    """
    SocketServer unittest class.
    """

    def __init__(self, *args, **kwargs):
        """
        Crating a server object whit default host and port and set timeout 0.1 second.

        :param args:
        :param kwargs:
        """
        super(TestSocketServer, self).__init__(*args, **kwargs)
        self.server = SocketServer(timeout=0.1)

    def testHost(self):
        """
        Test host string.

        :return:
        """
        self.assertEqual(self.server.getHost(), prop.HOST)

    def testPort(self):
        """
        Test port number.

        :return:
        """
        self.assertEqual(self.server.getPort(), prop.PORT)

    def testRunServer(self):
        """
        Test server run method and timeout.

        :return:
        """
        try:
            self.server.run()
        except socket.error as error:
            self.assertTrue(False, str(error))
        self.assertFalse(self.server.isRunning())
Exemplo n.º 5
0
import cv2
import numpy as np

import paths
from Server import SocketServer
import constants
import time, threading

serverData = SocketServer()
serverDataStr = ""


def send_periodicly():
    if serverDataStr != "":
        serverData.send(serverDataStr)
        print("send: " + serverDataStr)
    threading.Timer(10, send_periodicly).start()


def mask_preproscessing(img):

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2))

    # Fill any small holes
    closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel, iterations=1)
    # Remove noise
    opening = cv2.morphologyEx(closing, cv2.MORPH_OPEN, kernel, iterations=1)

    # Dilate to merge adjacent blobs
    dilation = cv2.dilate(opening, kernel, iterations=2)