Пример #1
0
    def PlayMonitor(self_MP):

        try:
            self_MP.ROIs  # if there are no ROIs yet, make an empty list
        except:
            self_MP.ROIs = []

        if not gbl.genmaskflag or self_MP.ROIs == []:
            self_MP.ROIs = gbl.loadROIsfromMaskFile(
                gbl.mask_file)  # new ROIs are ready

        self_MP.ROIframe, self_MP.redmask = gbl.makeMaskFrames(
            self_MP.ROIs, self_MP.initialSize
        )  # creates overlay of ROIs with source dimensions

        # each of the 3 video input classes has a "getImage" function
        self_MP.frame = self_MP.captureVideo.getImage()

        # multiply element by element to leave zeros where lines will be drawn
        self_MP.frame2 = np.multiply(self_MP.frame.copy(), self_MP.ROIframe)

        # add redmask to frame to turn lines red
        self_MP.frame3 = np.add(self_MP.frame2.copy(), self_MP.redmask)

        self_MP.newframe = cv2.resize(self_MP.frame3.copy(),
                                      dsize=self_MP.size)

        self_MP.bmp = wx.BitmapFromBuffer(self_MP.size[0], self_MP.size[1],
                                          self_MP.newframe.tostring())

        self_MP.keepPlaying = True
        self_MP.Show()
        gbl.genmaskflag = False
Пример #2
0
    def __init__(self, parent, mon_ID):
        self.mon_ID = gbl.mon_ID = mon_ID  # make sure the settings for this monitor are in the nicknames
        cfg.mon_dict_to_nicknames()
        self.mon_name = gbl.mon_name
        wx.Panel.__init__(self, parent, id=wx.ID_ANY, name=self.mon_name)

        # -------------------------------------------------------------------------------------------- source settings
        self.parent = parent
        self.loop = False  # never loop tracking
        self.keepPlaying = False  # don't start yet
        self.source = gbl.source
        self.source_type = gbl.source_type
        self.devnum = 0  # only one camera is currently supported
        self.fps = gbl.source_fps
        self.start_datetime = gbl.start_datetime
        self.mask_file = gbl.mask_file
        self.data_folder = gbl.data_folder
        self.outputprefix = os.path.join(
            self.data_folder,
            self.mon_name)  # path to folder where output will be saved
        self.console = self.consolePanel(
            parent, size=gbl.thumb_size)  # the output console

        # ---------------------------------------- use the sourcetype to create the correct type of object for capture
        if self.source_type == 0:
            self.captureMovie = VM.realCam(self.mon_ID, 1, devnum=0)
        elif self.source_type == 1:
            self.captureMovie = VM.virtualCamMovie(self.mon_ID,
                                                   1,
                                                   self.source,
                                                   loop=False)
        elif self.source_type == 2:
            self.captureMovie = VM.virtualCamFrames(self.mon_ID,
                                                    1,
                                                    self.source,
                                                    loop=False)

        (self.cols, self.rows) = self.size = self.captureMovie.initialSize

        self.ROIs = gbl.loadROIsfromMaskFile(
            self.mask_file
        )  # -----------------------------------------------------ROIs
Пример #3
0
    def __init__(self_MP,
                 parent,
                 mon_ID=gbl.mon_ID,
                 panelType='thumb',
                 loop=True):

        self_MP.mon_ID = mon_ID
        self_MP.mon_name = gbl.cfg_dict[self_MP.mon_ID]['mon_name']
        self_MP.panelType = panelType  # ----------------------------------------------- panel attributes
        if panelType == 'preview':
            self_MP.size = gbl.cfg_dict[self_MP.mon_ID]['preview_size']
            self_MP.fps = gbl.cfg_dict[self_MP.mon_ID]['preview_fps']
        elif panelType == 'thumb':
            self_MP.size = gbl.cfg_dict[0]['thumb_size']
            self_MP.fps = gbl.cfg_dict[0]['thumb_fps']
        else:
            self_MP.size = (320, 240)
            self_MP.fps = 1
            print('Unexpected panel type in class monitorPanel')

        wx.Panel.__init__(self_MP,
                          parent,
                          id=wx.ID_ANY,
                          size=self_MP.size,
                          name=self_MP.mon_name)

        self_MP.parent = parent
        self_MP.loop = loop
        self_MP.keepPlaying = False  # flag to start and stop video playback
        self_MP.source = gbl.cfg_dict[self_MP.mon_ID][
            'source']  # ----------------------------------- video source
        self_MP.source_type = gbl.cfg_dict[self_MP.mon_ID]['source_type']
        #        if self_MP.source_type == 0:     # get the device number if the panel source is a webcam
        #            self_MP.source = 0

        if gbl.genmaskflag:
            self_MP.ROIs = self_MP.Parent.ROIs
        else:
            self_MP.mask_file = gbl.cfg_dict[self_MP.mon_ID]['mask_file']
            try:  # ------ mask file may be corrupt
                self_MP.ROIs = gbl.loadROIsfromMaskFile(self_MP.mask_file)
            except:
                self_MP.ROIs = []

        self_MP.line_thickness = gbl.cfg_dict[self_MP.mon_ID]['line_thickness']

        self_MP.interval = 1000 / self_MP.fps

        self_MP.widgetMaker(
        )  # ------------------------------------------ panel widgets and sizers
        self_MP.sizers()
        self_MP.SetSize(self_MP.size)
        self_MP.SetMinSize(self_MP.GetSize())
        self_MP.SetBackgroundColour('#A9A9A9')
        self_MP.allowEditing = False

        # ---------------------------------------- use the sourcetype to create the correct type of object for capture
        if gbl.cfg_dict[self_MP.mon_ID]['source_type'] == 0:
            self_MP.captureVideo = realCam(self_MP.mon_ID,
                                           self_MP.fps,
                                           devnum=0)
        elif gbl.cfg_dict[self_MP.mon_ID]['source_type'] == 1:
            self_MP.captureVideo = virtualCamMovie(self_MP.mon_ID,
                                                   self_MP.fps,
                                                   self_MP.source,
                                                   loop=self_MP.loop)
        elif gbl.cfg_dict[self_MP.mon_ID]['source_type'] == 2:
            self_MP.captureVideo = virtualCamFrames(self_MP.mon_ID,
                                                    self_MP.fps,
                                                    self_MP.source,
                                                    loop=self_MP.loop)

        self_MP.initialSize = (
            self_MP.initialCols, self_MP.initialRows
        ) = self_MP.captureVideo.initialSize  # input frame size
        if self_MP.size > self_MP.captureVideo.initialSize:  # if size desired is bigger than input size
            self_MP.size = self_MP.captureVideo.initialSize  # reduce it to the input size
            if panelType == 'thumb':
                gbl.thumb_size = self_MP.size
            elif panelType == 'preview':
                gbl.preview_size = self_MP.size
            cfg.cfg_nicknames_to_dicts()

            self_MP.SetSize(self_MP.size)
            winsound.Beep(600, 200)
            gbl.statbar.SetStatusText('Input frame size is only ' +
                                      str(self_MP.size))

        # mouse coordinates for mask panels only
        if gbl.mon_ID != 0:
            self_MP.Bind(wx.EVT_LEFT_UP, self_MP.onLeftUp)
        # ---------------------------------------------------------------------- create a timer that will play the video
        self_MP.Bind(wx.EVT_PAINT, self_MP.onPaint)
        self_MP.Bind(wx.EVT_TIMER, self_MP.onNextFrame)
        self_MP.playTimer = wx.Timer(self_MP, id=wx.ID_ANY)
        self_MP.numberOfTimers = gbl.numberOfTimers + 1