Exemplo n.º 1
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        self.filenames = [
            "../images/Tower1.png", "../images/Tower2.png",
            "../images/Blank.png"
        ]

        self.grid = ZGridLayouter(self)

        self.image_views = [None, None, None]

        flags = cv2.IMREAD_COLOR

        # Create three imageviews.
        self.image_views[self.FIRST] = ZOpenCVImageView(
            self.grid, self.filenames[self.FIRST], flags)
        self.image_views[self.SECOND] = ZOpenCVImageView(
            self.grid, self.filenames[self.SECOND], flags)
        self.image_views[self.THIRD] = ZOpenCVImageView(
            self.grid, self.filenames[self.THIRD], flags)
        self.grid.add(self.image_views[self.FIRST], 0, 0)
        self.grid.add(self.image_views[self.SECOND], 0, 1)
        self.grid.add(self.image_views[self.THIRD], 1, 0, 1, 2)

        self.detector_id = self.DETECTOR_AKAZE

        self.detector = None

        self.show()
Exemplo n.º 2
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        self.raw_video_queue = mp.Queue()
        self.to_binarize_video_queue = mp.Queue()
        self.binarized_video_queue = mp.Queue()

        # Binarize initial settings
        #self.block_size         = 11
        #self.adaptive_method_id = 0;
        #self.threshold_type_id  = 0;

        self.binarize_video_settings_queue = mp.Queue()
        #binarize_video_settings_queue.put_nowait((self.block_size, \
        #                                          self.adaptive_method_id, \
        #                                          self.threshold_type_id))

        self.time_snapshot_seconds = None  # initialized to None . Used for rate limiting processing pipelines
        self.processing_rate_limit_hz = 20  # 30 Hz seems to be about the maximum if this camera

        self.raw_image_view = ZOpenCVImageView(self)
        self.binarized_image_view = self.BinarizedImageView(self)

        self.add(self.raw_image_view)
        self.add(self.binarized_image_view)

        title = name
        self.setWindowTitle(title)

        self.show()
Exemplo n.º 3
0
class MainView(ZApplicationView):
  
  # Constructor
  def __init__(self, title, x, y, width, height, device=0):
    super(MainView, self).__init__(title, x, y, width, height)
    self.video_capture = ZOpenCVVideoCapture()
    self.video_capture.open(device)
    self.image_view  = ZOpenCVImageView(self)
    self.add(self.image_view)
    
    title = str(device) + " - " + name
    self.setWindowTitle(title)
    
    self.show()
  
  # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view     
  def render(self):
    if self.video_capture.is_opened():
      frame = self.video_capture.read()
      if frame.any() != None:
        self.image_view.set_opencv_image(frame)
        self.image_view.update()
        return True
    else:
      # If the video_capture closed, return False
      return False
 
  def file_quit(self):
    self.terminated = True
    self.video_capture.close()
    self.close()
Exemplo n.º 4
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        self.filenames = [
            "../images/Lake2.png", "../images/Lake1.png", "../images/Blank.png"
        ]

        self.grid = ZGridLayouter(self)

        self.image_views = [None, None, None]

        flags = cv2.IMREAD_COLOR

        # 1 Create first imageview.
        self.image_views[self.FIRST] = ZOpenCVImageView(
            self.grid, self.filenames[self.FIRST], flags)
        self.image_views[self.SECOND] = ZOpenCVImageView(
            self.grid, self.filenames[self.SECOND], flags)
        self.image_views[self.THIRD] = ZOpenCVImageView(
            self.grid, self.filenames[self.THIRD], flags)
        self.grid.add(self.image_views[self.FIRST], 0, 0)
        self.grid.add(self.image_views[self.SECOND], 0, 1)
        self.grid.add(self.image_views[self.THIRD], 1, 0, 1, 2)

        self.mode = False  #cv2.cv.PANORAMA

        #self.stitcher = cv2.createStitcher(self.mode)
        self.stitcher = cv2.Stitcher_create(self.mode)

        self.stitch()

        self.show()
Exemplo n.º 5
0
class MainView(ZApplicationView):
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        filename = "../images/flower.png"

        # 1 Create an imageview in the main_widget
        self.image_view = ZOpenCVImageView(self)

        # 2 Load opencv image into the imageview.
        self.image_view.load_opencv_image(filename)

        # 3 Add the imageview to the main_layout
        self.add(self.image_view)

        self.set_filenamed_title(filename)

        self.show()

    # Default file_open method to read an image file by using ZOpenCVImageReader
    # and set the image read to the first area of ZDrawingArea.
    def file_open(self):
        options = QFileDialog.Options()
        filename, _ = QFileDialog.getOpenFileName(
            self,
            "FileOpenDialog",
            "",
            "All Files (*);;Image Files (*.png;*jpg;*.jpeg)",
            options=options)
        if filename:
            self.image_view.load_opencv_image(filename)
            self.set_filenamed_title(filename)
Exemplo n.º 6
0
 def __init__(self, title, x, y, width, height, device=0):
     super(MainView, self).__init__(title, x, y, width, height)
     self.video_capture = ZOpenCVVideoCapture()
     self.video_capture.open(device)
     self.image_view = ZOpenCVImageView(self)
     self.add(self.image_view)
     title = str(device)
     self.set_filenamed_title(title)
     self.show()
Exemplo n.º 7
0
  def __init__(self, title, x, y, width, height):
    super(MainView, self).__init__(title, x, y, width, height)
    
    self.raw_video_queue = mp.Queue()
    
    self.raw_image_view  = ZOpenCVImageView(self)
    self.binarized_image_view = self.BinarizedImageView(self)

    self.add(self.raw_image_view)
    self.add(self.binarized_image_view)

    title = name
    self.setWindowTitle(title)
    
    self.show()
Exemplo n.º 8
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        filename = "../images/flower.png"

        # 1 Create an imageview in the main_widget
        self.image_view = ZOpenCVImageView(self)

        # 2 Load opencv image into the imageview.
        self.image_view.load_opencv_image(filename)

        # 3 Add the imageview to the main_layout
        self.add(self.image_view)

        self.set_filenamed_title(filename)

        self.show()
Exemplo n.º 9
0
class MainView(ZApplicationView):

    # Constructor
    def __init__(self, title, x, y, width, height, device=0):
        super(MainView, self).__init__(title, x, y, width, height)
        self.video_capture = ZOpenCVVideoCapture()
        self.video_capture.open(device)
        self.image_view = ZOpenCVImageView(self)
        self.add(self.image_view)
        title = str(device)
        self.set_filenamed_title(title)
        self.show()

    # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view
    def render(self):
        if self.video_capture.is_opened():
            frame = self.video_capture.read()
            if frame.any() != None:
                self.image_view.set_opencv_image(frame)
                self.image_view.update()
                return True
        else:
            # If the video_capture closed, return False
            return False

    # Show FileOpenDialog and select an image file.
    def file_open(self):
        options = QFileDialog.Options()
        filename, _ = QFileDialog.getOpenFileName(
            self,
            "FileOpenDialog",
            "",
            "All Files (*);;Image Files (*.png;*jpg;*.jpeg)",
            options=options)
        if filename:
            self.video_capture.close()
            self.video_capture.open(filename)
            self.set_filenamed_title(filename)

    def file_quit(self):
        self.terminated = True
        self.video_capture.close()
        self.close()
Exemplo n.º 10
0
    def __init__(self, title, x, y, width, height, device=0):
        super(MainView, self).__init__(title, x, y, width, height)

        self.raw_video_queue = mp.Queue()
        self.message_queue = mp.Queue()
        """
    while queue_from_cam.empty():
      pass

    print 'getting image'
    from_queue = queue_from_cam.get()
    print 'saving image'
    cv2.imwrite('temp.png', from_queue)
    print 'image saved'    
    """

        #self.video_capture = ZOpenCVVideoCapture()
        #self.video_capture.open(device)

        self.image_view = ZOpenCVImageView(self)

        #self.image_view  = self.SourceImageView_1(self)

        #self.image_view  = self.SourceImageView(self)

        #filename = "images/flower.png"
        #self.image_view_2 = self.SourceImageView(self)
        #self.image_view_2 = self.SourceImageView_2(self)
        self.image_view_2 = ZOpenCVImageView(self)
        #self.load_file(filename)

        filename = "images/flower.png"
        self.image_view_3 = self.SourceImageView(self)
        self.load_file(filename)

        self.add(self.image_view)
        self.add(self.image_view_2)
        self.add(self.image_view_3)

        title = str(device) + " - " + name
        self.setWindowTitle(title)

        self.show()
Exemplo n.º 11
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        grid = ZGridLayouter(self)

        image_views = [None, None, None]
        filenames = [
            "../images/Pedestrian.png", "../images/Pedestrian8.png",
            "../images/MenInWhite2.jpg"
        ]

        flags = cv2.IMREAD_COLOR
        image_views[0] = ZOpenCVImageView(grid, filenames[0], flags)
        image_views[1] = ZOpenCVImageView(grid, filenames[1], flags)
        image_views[2] = ZOpenCVImageView(grid, filenames[2], flags)

        grid.add(image_views[0], 0, 0)
        grid.add(image_views[1], 0, 1)
        grid.add(image_views[2], 1, 0, 1, 2)

        self.show()
Exemplo n.º 12
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        self.image_views = [None, None, None]

        filenames = [
            "../images/flower.png", "../images/flower5.jpg",
            "../images/flower7.jpg"
        ]
        flags = [cv2.IMREAD_COLOR, cv2.IMREAD_GRAYSCALE, cv2.IMREAD_UNCHANGED]

        # Get the main horizontal layout from the parent ZApplicationView.

        # Create imageviews, load images from the filenames, and add those imageviews to the main layout.
        for i in range(len(self.image_views)):
            self.image_views[i] = ZOpenCVImageView(self)
            self.image_views[i].load_opencv_image(filenames[i], flags[i])
            self.add(self.image_views[i])

        self.show()
Exemplo n.º 13
0
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title,
                                       x,
                                       y,
                                       width,
                                       height,
                                       layout=Z.Grid)

        self.raw_video_queue = Queue()
        self.to_dft_video_queue = Queue()
        self.dft_settings_queue = Queue()

        self.dft_settings_queue.put_nowait([30])  # temporary

        self.dft_magnitude_unfiltered_video_queue = Queue()
        self.dft_magnitude_filtered_video_queue = Queue()
        self.filtered_video_queue = Queue()

        self.time_snapshot_seconds = None  # initialized to None . Used for rate limiting processing pipelines
        self.processing_rate_limit_hz = 5

        self.raw_image_view = ZOpenCVImageView(self)
        self.dft_magnitude_unfiltered_image_view = ZOpenCVImageView(self)
        self.dft_magnitude_filtered_image_view = ZOpenCVImageView(self)
        self.filtered_image_view = ZOpenCVImageView(self)

        #self.grid = ZGridLayouter(self)

        self.main_layouter.add(self.raw_image_view, 0, 0)
        self.main_layouter.add(self.dft_magnitude_unfiltered_image_view, 0, 1)
        self.main_layouter.add(self.dft_magnitude_filtered_image_view, 1, 1)
        self.main_layouter.add(self.filtered_image_view, 1, 0)

        title = name
        self.setWindowTitle(title)

        self.show()
Exemplo n.º 14
0
class MainView(ZApplicationView):
    class SourceImageView(ZOpenCVImageView):
        def __init__(self, parent):
            ZOpenCVImageView.__init__(self, parent)

        def load(self, filename):
            self.load_opencv_image(filename)
            self.update()

    """
  class SourceImageView_1(ZOpenCVImageView):
    def __init__(self, parent):
      ZOpenCVImageView.__init__(self, parent)
      
  class SourceImageView_2(ZOpenCVImageView):
    def __init__(self, parent):
      ZOpenCVImageView.__init__(self, parent)
  """

    # Constructor
    def __init__(self, title, x, y, width, height, device=0):
        super(MainView, self).__init__(title, x, y, width, height)

        self.raw_video_queue = mp.Queue()
        self.message_queue = mp.Queue()
        """
    while queue_from_cam.empty():
      pass

    print 'getting image'
    from_queue = queue_from_cam.get()
    print 'saving image'
    cv2.imwrite('temp.png', from_queue)
    print 'image saved'    
    """

        #self.video_capture = ZOpenCVVideoCapture()
        #self.video_capture.open(device)

        self.image_view = ZOpenCVImageView(self)

        #self.image_view  = self.SourceImageView_1(self)

        #self.image_view  = self.SourceImageView(self)

        #filename = "images/flower.png"
        #self.image_view_2 = self.SourceImageView(self)
        #self.image_view_2 = self.SourceImageView_2(self)
        self.image_view_2 = ZOpenCVImageView(self)
        #self.load_file(filename)

        filename = "images/flower.png"
        self.image_view_3 = self.SourceImageView(self)
        self.load_file(filename)

        self.add(self.image_view)
        self.add(self.image_view_2)
        self.add(self.image_view_3)

        title = str(device) + " - " + name
        self.setWindowTitle(title)

        self.show()

    # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view
    def render(self):

        if not self.raw_video_queue.empty():
            #frame = self.raw_video_queue.get_nowait()
            frame = self.raw_video_queue.get()
            """
      if self.video_capture.is_opened():
        frame = self.video_capture.read()
      """
            if frame.any() != None:
                self.image_view.set_opencv_image(frame)
                self.image_view.update()

                self.image_view_2.set_opencv_image(frame)
                self.image_view_2.update()

                return True
        else:
            # If the video_capture closed, return False
            return False

    def load_file(self, filename):
        self.image_view_3.load(filename)
        self.set_filenamed_title(filename)

    def file_quit(self):
        self.terminated = True
        #self.video_capture.close()
        #self.message_queue.put("exit")
        #self.message_queue.put_nowait("exit")
        print("2")
        #sleep(5)
        #while not self.raw_video_queue.empty():
        #  frame = self.raw_video_queue.get_nowait()
        #self.close()
        print("3")
        #self.terminated = True

    def closeEvent(self, ce):
        self.terminated = True
        #self.video_capture.close()
        #self.message_queue.put_nowait("exit")
        print("2")
        #sleep(5)
        #while not self.raw_video_queue.empty():
        #  frame = self.raw_video_queue.get_nowait()
        #self.close()
        print("3")
Exemplo n.º 15
0
from SOL4Py.ZImageView import ZImageView
from SOL4Py.opencv.ZOpenCVImageView import ZOpenCVImageView

#---------------------------------------------------------------------
#
if __name__ == '__main__':
    applet = QApplication(sys.argv)
    appview = QWidget()
    appview.setWindowTitle(sys.argv[0])
    grid = QGridLayout(appview)
    image_views = [None, None, None, None, None, None]
    filenames = [
        "../images/flower.png", "../images/flower1.jpg",
        "../images/flower2.jpg", "../images/flower3.jpg",
        "../images/flower7.jpg"
    ]

    for i in range(len(filenames)):
        image_views[i] = ZOpenCVImageView(appview)  #, 0, 0, 400, 300)
        image_views[i].load_opencv_image(filenames[i], i % 3)
        y = int(i % 3)
        x = int(i / 3)

        grid.addWidget(image_views[i], x, y)

    appview.setGeometry(40, 40, 800, 400)
    appview.show()

    applet.exec_()
Exemplo n.º 16
0
class MainView(ZApplicationView):
    class BinarizedImageView(ZOpenCVImageView):
        def __init__(self, parent):
            ZOpenCVImageView.__init__(self, parent)

    # Constructor
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title, x, y, width, height)

        self.raw_video_queue = mp.Queue()
        self.to_binarize_video_queue = mp.Queue()
        self.binarized_video_queue = mp.Queue()

        # Binarize initial settings
        #self.block_size         = 11
        #self.adaptive_method_id = 0;
        #self.threshold_type_id  = 0;

        self.binarize_video_settings_queue = mp.Queue()
        #binarize_video_settings_queue.put_nowait((self.block_size, \
        #                                          self.adaptive_method_id, \
        #                                          self.threshold_type_id))

        self.time_snapshot_seconds = None  # initialized to None . Used for rate limiting processing pipelines
        self.processing_rate_limit_hz = 20  # 30 Hz seems to be about the maximum if this camera

        self.raw_image_view = ZOpenCVImageView(self)
        self.binarized_image_view = self.BinarizedImageView(self)

        self.add(self.raw_image_view)
        self.add(self.binarized_image_view)

        title = name
        self.setWindowTitle(title)

        self.show()

    def add_control_pane(self, fixed_width=220):
        # Control pane widget
        self.vpane = ZVerticalPane(self, fixed_width)

        #"""
        self.block_size = 11
        self.adaptive_method_id = 0
        self.threshold_type_id = 0
        #"""

        self.methods = {
            "ADAPTIVE_THRESH_MEAN_C": cv2.ADAPTIVE_THRESH_MEAN_C,
            "ADAPTIVE_THRESH_GAUSSIAN_C": cv2.ADAPTIVE_THRESH_GAUSSIAN_C
        }
        self.types = {
            "THRESH_BINARY": cv2.THRESH_BINARY,
            "THRESH_BINARY_INV": cv2.THRESH_BINARY_INV
        }

        self.adaptive_method = ZLabeledComboBox(self.vpane, "AdaptiveMethod")
        self.adaptive_method.add_items(list(self.methods.keys()))
        self.adaptive_method.add_activated_callback(
            self.adaptive_method_activated)

        self.threshold_type = ZLabeledComboBox(self.vpane, "ThresholdType")
        self.threshold_type.add_items(list(self.types.keys()))
        self.threshold_type.add_activated_callback(
            self.threshold_type_activated)

        self.labeled_slider = ZLabeledSlider(self.vpane,
                                             "BlockSize",
                                             take_odd=True,
                                             minimum=3,
                                             maximum=43,
                                             value=self.block_size,
                                             fixed_width=200)
        self.labeled_slider.add_value_changed_callback(
            self.slider_value_changed)

        self.vpane.add(self.adaptive_method)
        self.vpane.add(self.threshold_type)
        self.vpane.add(self.labeled_slider)

        self.set_right_dock(self.vpane)

    def slider_value_changed(self, value):
        self.block_size = int(value)
        if self.block_size % 2 == 0:
            # Block size should be odd.
            self.block_size = int((self.block_size * 2) / 2 + 1)
        #print("slider_value_changed:{}".format(block_size))

        #self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)

        settings = (self.adaptive_method_id, self.threshold_type_id,
                    self.block_size)
        self.binarize_video_settings_queue.put_nowait(settings)

    def adaptive_method_activated(self, text):
        #print("adaptive_method_activated:{}".format(text))
        self.adaptive_method_id = self.methods[text]

        #self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)

        settings = (self.adaptive_method_id, self.threshold_type_id,
                    self.block_size)
        self.binarize_video_settings_queue.put_nowait(settings)

    def threshold_type_activated(self, text):
        #print("threshold_type_activated:{}".format(text))
        self.threshold_type_id = self.types[text]

        #self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)

        settings = (self.adaptive_method_id, self.threshold_type_id,
                    self.block_size)
        self.binarize_video_settings_queue.put_nowait(settings)

    # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view
    def render(self):

        return_true = False
        #return_true = True
        #"""
        if not self.raw_video_queue.empty():
            raw_frame = self.raw_video_queue.get_nowait()

            if raw_frame.any() != None:
                self.raw_image_view.set_opencv_image(raw_frame)
                self.raw_image_view.update()

                # Send frame to processing queue
                # rate limited
                current_time_seconds = time()

                if self.time_snapshot_seconds == None:
                    self.time_snapshot_seconds = current_time_seconds

                if current_time_seconds > self.time_snapshot_seconds:  # Avoid dividing by zero

                    #print(1/(current_time_seconds-self.time_snapshot_seconds))

                    if ((1 /
                         (current_time_seconds - self.time_snapshot_seconds))
                            <= self.processing_rate_limit_hz):  # Rate limit

                        #print("Sending raw frame for further processing!")

                        self.to_binarize_video_queue.put_nowait(raw_frame)

                        self.time_snapshot_seconds = current_time_seconds

                return_true = True

        if not self.binarized_video_queue.empty():
            binarized_frame = self.binarized_video_queue.get_nowait()

            if binarized_frame.any() != None:
                self.binarized_image_view.set_opencv_image(binarized_frame)
                self.binarized_image_view.update()

                return_true = True
        #"""
        if return_true:
            return True
        else:
            return False

    def file_quit(self):
        self.terminated = True

    def closeEvent(self, ce):
        self.terminated = True
Exemplo n.º 17
0
 def __init__(self, parent):
   ZOpenCVImageView.__init__(self, parent)
   self.noised_image = None
Exemplo n.º 18
0
import traceback

import cv2
import errno

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

sys.path.append('../')

from SOL4Py.opencv.ZOpenCVImageView import ZOpenCVImageView

#---------------------------------------------------------------------
# Unit test
#
if __name__ == '__main__':
    try:
        applet = QApplication(sys.argv)
        image_view = ZOpenCVImageView(parent=None)

        image_view.load_opencv_image("../images/flower.png",
                                     cv2.IMREAD_GRAYSCALE)
        image_view.setGeometry(40, 40, 400, 300)
        image_view.show()

        applet.exec_()

    except:
        traceback.print_exc()
Exemplo n.º 19
0
 def __init__(self, parent):
     ZOpenCVImageView.__init__(self, parent)
     self.gray_image = None
Exemplo n.º 20
0
class MainView(ZApplicationView):
  
  class BinarizedImageView(ZOpenCVImageView):
    def __init__(self, parent):
      ZOpenCVImageView.__init__(self, parent)
      
    def load_source_image(self, source_image):
      image =  cv2.GaussianBlur(source_image, (3,3), 0, 0, borderType = cv2.BORDER_DEFAULT );
      #image =  cv2.GaussianBlur(source_image, (3,3), 0, 0)

      self.gray_image = cv2.cvtColor(source_image, cv2.COLOR_RGB2GRAY)
             
    def binarize(self, adaptive_method_id, threshold_type_id, block_size):
      MAX_PIXEL_VALUE = 255
      C               = 9.0
    
      binarized_image = cv2.adaptiveThreshold(self.gray_image,  MAX_PIXEL_VALUE, 
          adaptive_method_id, threshold_type_id, block_size,  C);
          
      #return binarized_image
      self.set_opencv_image(binarized_image)
      self.update()
  
  # Constructor
  def __init__(self, title, x, y, width, height):
    super(MainView, self).__init__(title, x, y, width, height)
    
    self.raw_video_queue = mp.Queue()
    
    self.raw_image_view  = ZOpenCVImageView(self)
    self.binarized_image_view = self.BinarizedImageView(self)

    self.add(self.raw_image_view)
    self.add(self.binarized_image_view)

    title = name
    self.setWindowTitle(title)
    
    self.show()
  
  def add_control_pane(self, fixed_width=220):
    # Control pane widget
    self.vpane = ZVerticalPane(self, fixed_width)
    
    self.block_size         = 11
    self.adaptive_method_id = 0;
    self.threshold_type_id  = 0;

    
    self.methods = {"ADAPTIVE_THRESH_MEAN_C": cv2.ADAPTIVE_THRESH_MEAN_C, 
                    "ADAPTIVE_THRESH_GAUSSIAN_C": cv2.ADAPTIVE_THRESH_GAUSSIAN_C}
    self.types   = {"THRESH_BINARY":  cv2.THRESH_BINARY  , 
                    "THRESH_BINARY_INV": cv2.THRESH_BINARY_INV }
    
    self.adaptive_method = ZLabeledComboBox(self.vpane, "AdaptiveMethod")
    self.adaptive_method.add_items(list(self.methods.keys() ))
    self.adaptive_method.add_activated_callback(self.adaptive_method_activated)
    
    self.threshold_type  = ZLabeledComboBox(self.vpane, "ThresholdType")
    self.threshold_type.add_items(list(self.types.keys()) )
    self.threshold_type.add_activated_callback(self.threshold_type_activated)
    
    self.labeled_slider = ZLabeledSlider(self.vpane, "BlockSize", take_odd =True,  
              minimum=3, maximum=43, value=self.block_size, fixed_width=200)
    self.labeled_slider.add_value_changed_callback(self.slider_value_changed)
    
    self.vpane.add(self.adaptive_method)
    self.vpane.add(self.threshold_type)    
    self.vpane.add(self.labeled_slider)

    self.set_right_dock(self.vpane)

  def slider_value_changed(self, value):
    self.block_size = int(value)
    if self.block_size % 2 == 0:
      # Block size should be odd.
      self.block_size = int((self.block_size * 2)/2 + 1)
    #print("slider_value_changed:{}".format(block_size))
    self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
    
  def adaptive_method_activated(self, text):
    #print("adaptive_method_activated:{}".format(text))
    self.adaptive_method_id = self.methods[text]
    
    self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
     
  def threshold_type_activated(self, text):
    #print("threshold_type_activated:{}".format(text))
    self.threshold_type_id = self.types[text]
    self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
    
  # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view     
  def render(self):
    
    #return_true = False
    
    if not self.raw_video_queue.empty():
      raw_frame = self.raw_video_queue.get_nowait()
      
      if raw_frame.any() != None:
        self.raw_image_view.set_opencv_image(raw_frame)
        self.raw_image_view.update()
        
        
        self.binarized_image_view.load_source_image(raw_frame)
        self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
        
        
        return True
      
    """
      
    if not self.binarized_video_queue.empty():
      binarized_frame = self.binarized_video_queue.get_notwait()
      if binarized_frame.any() != None:
        self.binarized_image_view.set_opencv_image(binarized_frame)
        self.binarized_image_view.update()
        return_true = True
    
    if return_true:
      return True
    else:
      return False
    """
    return False
    
  """
  def load_file(self, filename):
    self.image_view_3.load(filename)
    self.set_filenamed_title(filename)
 """
  
  def file_quit(self):
    self.terminated = True
    
  def closeEvent(self, ce):
    self.terminated = True
Exemplo n.º 21
0
 def __init__(self, parent):
     ZOpenCVImageView.__init__(self, parent)
     self.source_image = None
Exemplo n.º 22
0
 def __init__(self, parent, filename=None, flags=cv2.IMREAD_COLOR):
     ZOpenCVImageView.__init__(self, parent, filename, flags)
     src_mage = self.get_opencv_image()
     self.gray_image = cv2.cvtColor(src_mage, cv2.COLOR_BGR2GRAY)
     print("BinarizedImage")
     self.binarized_image = None
Exemplo n.º 23
0
 def __init__(self, parent, filename=None, flags=cv2.IMREAD_COLOR):
     ZOpenCVImageView.__init__(self, parent, filename, flags)
Exemplo n.º 24
0
 def __init__(self, parent):
     ZOpenCVImageView.__init__(self, parent)
Exemplo n.º 25
0
class MainView(ZApplicationView):
    # Constructor
    def __init__(self, title, x, y, width, height):
        super(MainView, self).__init__(title,
                                       x,
                                       y,
                                       width,
                                       height,
                                       layout=Z.Grid)

        self.raw_video_queue = Queue()
        self.to_dft_video_queue = Queue()
        self.dft_settings_queue = Queue()

        self.dft_settings_queue.put_nowait([30])  # temporary

        self.dft_magnitude_unfiltered_video_queue = Queue()
        self.dft_magnitude_filtered_video_queue = Queue()
        self.filtered_video_queue = Queue()

        self.time_snapshot_seconds = None  # initialized to None . Used for rate limiting processing pipelines
        self.processing_rate_limit_hz = 5

        self.raw_image_view = ZOpenCVImageView(self)
        self.dft_magnitude_unfiltered_image_view = ZOpenCVImageView(self)
        self.dft_magnitude_filtered_image_view = ZOpenCVImageView(self)
        self.filtered_image_view = ZOpenCVImageView(self)

        #self.grid = ZGridLayouter(self)

        self.main_layouter.add(self.raw_image_view, 0, 0)
        self.main_layouter.add(self.dft_magnitude_unfiltered_image_view, 0, 1)
        self.main_layouter.add(self.dft_magnitude_filtered_image_view, 1, 1)
        self.main_layouter.add(self.filtered_image_view, 1, 0)

        title = name
        self.setWindowTitle(title)

        self.show()

    #"""
    def add_control_pane(self, fixed_width=220):
        # Control pane widget
        self.vpane = ZVerticalPane(self, fixed_width)

        self.filter_width_div_two = 30
        #self.adaptive_method_id = 0;
        #self.threshold_type_id  = 0;
        """
    self.methods = {"ADAPTIVE_THRESH_MEAN_C": cv2.ADAPTIVE_THRESH_MEAN_C, 
                    "ADAPTIVE_THRESH_GAUSSIAN_C": cv2.ADAPTIVE_THRESH_GAUSSIAN_C}
    self.types   = {"THRESH_BINARY":  cv2.THRESH_BINARY  , 
                    "THRESH_BINARY_INV": cv2.THRESH_BINARY_INV }
    
    self.adaptive_method = ZLabeledComboBox(self.vpane, "AdaptiveMethod")
    self.adaptive_method.add_items(list(self.methods.keys() ))
    self.adaptive_method.add_activated_callback(self.adaptive_method_activated)
    
    self.threshold_type  = ZLabeledComboBox(self.vpane, "ThresholdType")
    self.threshold_type.add_items(list(self.types.keys()) )
    self.threshold_type.add_activated_callback(self.threshold_type_activated)
    """
        self.labeled_slider = ZLabeledSlider(self.vpane,
                                             "Filter width // 2 ",
                                             take_odd=True,
                                             minimum=0,
                                             maximum=480 // 2,
                                             value=self.filter_width_div_two,
                                             fixed_width=200)
        self.labeled_slider.add_value_changed_callback(
            self.slider_value_changed)

        #self.vpane.add(self.adaptive_method)
        #self.vpane.add(self.threshold_type)
        self.vpane.add(self.labeled_slider)

        #self.set_right_dock(self.vpane)
        #self.grid = ZGridLayouter(self)

        self.main_layouter.add(self.vpane, 1, 2)

    def slider_value_changed(self, value):
        self.block_size = int(value)
        #if self.block_size % 2 == 0:
        #  # Block size should be odd.
        #  self.block_size = int((self.block_size * 2)/2 + 1)
        #print("slider_value_changed:{}".format(block_size))

        #self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
        """
    # Send frame to processing queue rate limited
    current_time_seconds = time()
    
    if self.time_snapshot_seconds == None:
      self.time_snapshot_seconds = current_time_seconds
    
    if ((1/(current_time_seconds-self.time_snapshot_seconds)) <= self.processing_rate_limit_hz): # Rate limit
        """

        settings = [self.block_size]

        self.dft_settings_queue.put_nowait(settings)

    #"""
    """
  def adaptive_method_activated(self, text):
    #print("adaptive_method_activated:{}".format(text))
    self.adaptive_method_id = self.methods[text]
    
    #self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
    
    settings = (self.adaptive_method_id, self.threshold_type_id, self.block_size)
    self.binarize_video_settings_queue.put_nowait(settings)
     
  def threshold_type_activated(self, text):
    #print("threshold_type_activated:{}".format(text))
    self.threshold_type_id = self.types[text]
    
    #self.binarized_image_view.binarize(self.adaptive_method_id, self.threshold_type_id, self.block_size)
    
    settings = (self.adaptive_method_id, self.threshold_type_id, self.block_size)
    self.binarize_video_settings_queue.put_nowait(settings)
  """

    # Read a frame from a video buffer of the video capture, and set it the image view to draw it on the imag view
    def render(self):

        return_true = False

        if not self.raw_video_queue.empty():
            raw_frame = self.raw_video_queue.get_nowait()

            if raw_frame.any() != None:
                self.raw_image_view.set_opencv_image(raw_frame)
                self.raw_image_view.update()

                # Send frame to processing queue rate limited
                current_time_seconds = time()

                if self.time_snapshot_seconds == None:
                    self.time_snapshot_seconds = current_time_seconds

                if current_time_seconds > self.time_snapshot_seconds:  # Avoid dividing by zero

                    #print(1/(current_time_seconds-self.time_snapshot_seconds))

                    if ((1 /
                         (current_time_seconds - self.time_snapshot_seconds))
                            <= self.processing_rate_limit_hz):  # Rate limit

                        #print("Sending raw frame for further processing!")

                        self.to_dft_video_queue.put_nowait(raw_frame)

                        self.time_snapshot_seconds = current_time_seconds

                return_true = True

        if not self.dft_magnitude_unfiltered_video_queue.empty():
            dft_magnitude_unfiltered_frame = \
            self.dft_magnitude_unfiltered_video_queue.get_nowait()

            if dft_magnitude_unfiltered_frame.any() != None:
                self.dft_magnitude_unfiltered_image_view.set_opencv_image(
                    np.uint8(dft_magnitude_unfiltered_frame))
                self.dft_magnitude_unfiltered_image_view.update()

                return_true = True

        if not self.dft_magnitude_filtered_video_queue.empty():
            dft_magnitude_filtered_frame = \
            self.dft_magnitude_filtered_video_queue.get_nowait()

            if dft_magnitude_filtered_frame.any() != None:
                self.dft_magnitude_filtered_image_view.set_opencv_image(
                    np.uint8(dft_magnitude_filtered_frame))
                self.dft_magnitude_filtered_image_view.update()

                return_true = True

        if not self.filtered_video_queue.empty():
            filtered_video_frame = \
            self.filtered_video_queue.get_nowait()

            if filtered_video_frame.any() != None:
                self.filtered_image_view.set_opencv_image(
                    np.uint8(filtered_video_frame))
                self.filtered_image_view.update()

                return_true = True

        if return_true:
            return True
        else:
            return False

    def file_quit(self):
        self.terminated = True

    def closeEvent(self, ce):
        self.terminated = True