Exemple #1
0
    def _select_device_by_index_func(self, source):
        self._cleanup_driver_func()
        self.lock.acquire()
        try:
            self.ffi = FFI()
            self.hdmi_in = HDMI('in', init_timeout=10)
            self.hdmi_in.start()

            # TODO: under development
            if False and self._enable_output:
                self.hdmi_out = HDMI('out', frame_list=self.hdmi_in.frame_list)
                mode = self._select_output_mode(self.hdmi_in.frame_width(), self.hdmi_in.frame_height())
                self.hdmi_out.mode(mode)

            time.sleep(1)

            if self.hdmi_out is not None:
                self.hdmi_out.start()

            self.hdmi_in_geom = \
                (self.hdmi_in.frame_width(), self.hdmi_in.frame_height())

            self.framebuffer = []
            for i in range(video.VDMA_DICT['NUM_FSTORES']):
                pointer = self.ffi.cast('uint8_t *', self.hdmi_in.frame_addr(i))
                #buffer_size = video.MAX_FRAME_WIDTH * video.MAX_FRAME_HEIGHT * 3 # 3 == sizeof(RGB)
                buffer_size = self.hdmi_in_geom[0] * self.hdmi_in_geom[1] * 3
                _bf = self.ffi.buffer(pointer, buffer_size)
                bf = np.frombuffer(_bf,np.uint8).reshape(self.hdmi_in_geom[1],self.hdmi_in_geom[0],3)
                #self.framebuffer.append(bf[:self.hdmi_in_geom[1],:self.hdmi_in_geom[0],:])
                self.framebuffer.append(bf)

            IkaUtils.dprint('%s: resolution %dx%d' % (self, self.hdmi_in_geom[0], self.hdmi_in_geom[1]))

        except:
            print(traceback.format_exc())
            self.hdmi_in = None
            self.hdmi_out = None
            if self.framebuffer is not None:
                for fb in self.framebuffer:
                    del fb
            self.ffi = None

        finally:
            self.lock.release()

        self.systime_base = time.time()
        return self.is_active()
Exemple #2
0
    def _select_device_by_index_func(self, source):
        self.lock.acquire()
        try:
            if self.is_active():
                if self.hdmi_out is not None:
                    self.hdmi_out.stop()

                if self.hdmi_in is not None:
                    self.hdmi_in.stop()

            self.reset()
            self.hdmi_in = HDMI('in', init_timeout=10)
            self.hdmi_out = HDMI('out', frame_list=self.hdmi_in.frame_list)
            self.hdmi_out.mode(4)  # 2=720p, 4=1080p
            time.sleep(1)

            #self.hdmi_out.stop()
            #self.hdmi_in.stop()
            #time.sleep(1)

            self.hdmi_out.start()
            self.hdmi_in.start()

            self.hdmi_in_geom = (self.hdmi_in.frame_width(),
                                 self.hdmi_in.frame_height())

            print('HDMI is capturing a video source of resolution %dx%d' %
                  self.hdmi_in_geom)

            #if not self.hdmi_in.isOpened():
            #    IkaUtils.dprint(
            #        '%s: cv2.VideoCapture() failed to open the device' % self)
            #    self.hdmi_in = None

        except:
            print(traceback.format_exc())
            self.hdmi_in = None
            self.hdmi_out = None

        finally:
            self.lock.release()

        self.systime_base = time.time()
        return self.is_active()
    def connect_HDMI(self):
        """
        Connect to HDMI
        """
        if not self.running:
            try:
                self.hdmi_in = HDMI('in',video_mode=4,init_timeout=2)
                print("HDMI in configured")
                self.width = self.hdmi_in.frame_width()
                self.height = self.hdmi_in.frame_height()
                self.hdmi_out = HDMI('out',video_mode=0,frame_list=self.hdmi_in.frame_list)
                print("HDMI out configured")

                self.hdmi_out.start()
                self.hdmi_in.start()
                self.running = True
                return True
            except Exception as e:
                self.running = False
                # print(e)
                return False
        print("Already Connected")
        return True
Exemple #4
0
    def _select_device_by_index_func(self, source):
        self.lock.acquire()
        try:
            if self.is_active():
                if self.hdmi_out is not None:
                    self.hdmi_out.stop()

                if self.hdmi_in is not None:
                    self.hdmi_in.stop()

            self.reset()
            self.hdmi_in = HDMI('in', init_timeout=10)
            if self._enable_output:
                self.hdmi_out = HDMI('out', frame_list=self.hdmi_in.frame_list)
                self.hdmi_out.mode(2)  # 2=720p, 4=1080p

            time.sleep(1)

            if self.hdmi_out is not None:
                self.hdmi_out.start()
            self.hdmi_in.start()

            self.hdmi_in_geom = \
                (self.hdmi_in.frame_width(), self.hdmi_in.frame_height())

            IkaUtils.dprint('%s: resolution %dx%d' % self.hdmi_in_geom)

        except:
            print(traceback.format_exc())
            self.hdmi_in = None
            self.hdmi_out = None

        finally:
            self.lock.release()

        self.systime_base = time.time()
        return self.is_active()
Exemple #5
0
##########################################################
###### CREATE Video Input/Output Drivers #################
##########################################################

print("Program Started\nInstantiating Drivers")

from pynq import Overlay
import numpy as np
import cv2
from pynq.drivers.video import HDMI

Overlay("base.bit").download()

# monitor configuration: 640*480 @ 60Hz
hdmi_out = HDMI('out', video_mode=HDMI.VMODE_640x480)
hdmi_out.start()

# monitor (output) frame buffer size
frame_out_w = 1920
frame_out_h = 1080
# camera (input) configuration
frame_in_w = 640
frame_in_h = 480

# initialize camera from OpenCV
from pynq.drivers.video import Frame

webcam = cv2.VideoCapture(0)
webcam.set(cv2.CAP_PROP_FRAME_WIDTH, frame_in_w)
webcam.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_in_h)
Exemple #6
0
# ## 1. Start HDMI output
# ### Step 1: Load the overlay

# In[1]:

from pynq import Overlay

Overlay("base.bit").download()

# ### Step 2: Initialize HDMI I/O

# In[2]:

from pynq.drivers.video import HDMI

hdmi_out = HDMI('out')
hdmi_out.start()

# ## 2. Applying OpenCV filters on Webcam input
# ### Step 1: Initialize Webcam and set HDMI Out resolution

# In[3]:

# monitor configuration: 640*480 @ 60Hz
hdmi_out.mode(HDMI.VMODE_640x480)
hdmi_out.start()
# monitor (output) frame buffer size
frame_out_w = 1920
frame_out_h = 1080
# camera (input) configuration
frame_in_w = 640