Beispiel #1
0
    def __init__(self, webconf):
        self.webconf = webconf
        self._picam = PiCam()
        config = ConfigParser.ConfigParser()
        config.readfp(open('/etc/raspadmin/picam.conf'))
        self._servoX = config.get("PICAM", "useServoXaxis")
        if self._servoX == "1":
            self._useGPIOPower = config.get("PICAM", "useGpioPowerSwitch")
            self._servoPwNum = int(config.get("PICAM",
                                              "servoControlPinNumber"))
            self._maxServoPulse = int(config.get("PICAM", "maxServoPulse"))
            self._minServoPulse = int(config.get("PICAM", "minServoPulse"))
            self._defaultServoPulse = int(
                config.get("PICAM", "defaultServoPulse"))
            self._stepServoPulse = int(config.get("PICAM", "stepServoPulse"))
            self._servo = ServoManager(self._servoPwNum, self._minServoPulse,
                                       self._maxServoPulse,
                                       self._defaultServoPulse,
                                       self._stepServoPulse)
            if self._useGPIOPower == "1":
                self._switchGPIONum = int(
                    config.get("PICAM", "switchPinNumber"))
                self._servo.setSwitchMode(self._switchGPIONum)

            self._servo.start()
Beispiel #2
0
	def __init__(self,webconf):
		self.webconf=webconf
		self._picam = PiCam()
                config = ConfigParser.ConfigParser()
                config.readfp(open('/etc/raspadmin/picam.conf'))
		self._servoX=config.get("PICAM", "useServoXaxis")
		if self._servoX=="1":
			self._useGPIOPower       = config.get("PICAM", "useGpioPowerSwitch")
			self._servoPwNum         = int(config.get("PICAM","servoControlPinNumber"))
			self._maxServoPulse      = int(config.get("PICAM","maxServoPulse"))
			self._minServoPulse      = int(config.get("PICAM","minServoPulse"))
			self._defaultServoPulse  = int(config.get("PICAM","defaultServoPulse"))
			self._stepServoPulse     = int(config.get("PICAM","stepServoPulse"))
			self._servo = ServoManager(self._servoPwNum,self._minServoPulse, self._maxServoPulse, self._defaultServoPulse,self._stepServoPulse)
			if self._useGPIOPower == "1":
				self._switchGPIONum=int(config.get("PICAM", "switchPinNumber"))
				self._servo.setSwitchMode(self._switchGPIONum)
			
			self._servo.start()
Beispiel #3
0
class WebManager(WebStructure.WebAbstract):
    def __init__(self, webconf):
        self.webconf = webconf
        self._picam = PiCam()
        config = ConfigParser.ConfigParser()
        config.readfp(open('/etc/raspadmin/picam.conf'))
        self._servoX = config.get("PICAM", "useServoXaxis")
        if self._servoX == "1":
            self._useGPIOPower = config.get("PICAM", "useGpioPowerSwitch")
            self._servoPwNum = int(config.get("PICAM",
                                              "servoControlPinNumber"))
            self._maxServoPulse = int(config.get("PICAM", "maxServoPulse"))
            self._minServoPulse = int(config.get("PICAM", "minServoPulse"))
            self._defaultServoPulse = int(
                config.get("PICAM", "defaultServoPulse"))
            self._stepServoPulse = int(config.get("PICAM", "stepServoPulse"))
            self._servo = ServoManager(self._servoPwNum, self._minServoPulse,
                                       self._maxServoPulse,
                                       self._defaultServoPulse,
                                       self._stepServoPulse)
            if self._useGPIOPower == "1":
                self._switchGPIONum = int(
                    config.get("PICAM", "switchPinNumber"))
                self._servo.setSwitchMode(self._switchGPIONum)

            self._servo.start()

    def get_image(self):
        my_stream = io.BytesIO()
        self._picam.getPicture(my_stream)
        return {'image': base64.b64encode(my_stream.getvalue())}

    def noError(self):
        return WebStructure.HttpContext(statuscode=200,
                                        content=json.dumps({
                                            'error':
                                            0,
                                            'errorstr':
                                            'No Error'
                                        }),
                                        template=None,
                                        mimetype='text/html')

    def webService(self, post):
        if not 'alphanum_action' in post.keys():
            return WebStructure.HttpContext(statuscode=200,
                                            content=None,
                                            template=None,
                                            mimetype='text/html')
        action = post['alphanum_action']

        if action == 'light_inc':
            self._picam.increaseBrightNess()
            return self.noError()
        elif action == 'light_dec':
            self._picam.decreaseBrightNess()
            return self.noError()
        elif action == 'exposure_inc':
            self._picam.increaseEvCp()
            return self.noError()
        elif action == 'exposure_dec':
            self._picam.decreaseEvCp()
            return self.noError()
        elif action == 'movex_inc' and self._servoX == "1":
            self._servo.inc()
            return self.noError()
        elif action == 'movex_dec' and self._servoX == "1":
            self._servo.dec()
            return self.noError()

        return WebStructure.HttpContext(statuscode=200,
                                        content=None,
                                        template=None,
                                        mimetype='text/html')

    def get_html(self, http_context):
        template = ['header.tpl', 'picam/picam.tpl', 'footer.tpl']
        sessionid = http_context.sessionid
        sessionvars = http_context.session.get_vars(sessionid)
        post = http_context.http_post

        if http_context.suburl == 'getimage' and self._picam.isActive():
            content = json.dumps(self.get_image())
            return WebStructure.HttpContext(statuscode=200,
                                            content=content,
                                            template=None,
                                            mimetype='text/html')
        elif http_context.suburl == 'ws':
            return self.webService(post)
        elif http_context.suburl == 'start':
            self._picam.start()
        elif http_context.suburl == 'stop':
            self._picam.stop()
        content = {
            'isActive': self._picam.isActive(),
            'token': sessionvars['posttoken'],
            'manageServoX': self._servoX,
            'gpioSwitch': self._useGPIOPower
        }
        return WebStructure.HttpContext(statuscode=200,
                                        content=content,
                                        template=template,
                                        mimetype='text/html')

    def get_module_name(self):
        return "PiCam"
Beispiel #4
0
face_image = np.array((FACE_WIDTH, FACE_WIDTH,3), dtype=int)

def detect_face(frame):
    global face_image
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # 이미지에서 얼굴을 검출합니다.
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    # 얼굴이 검출되었다면 얼굴 위치에 대한 좌표 정보를 리턴받습니다.

    for (x,y,w,h) in faces:
        # 원본 이미지에 얼굴의 위치를 표시
        # cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
        minLength = min(w, h)
        if minLength < 150: break
        width = max(w, h)

        # 얼굴 부분 검출
        # face_image = frame[y:y+h, x:x+w].copy()
        x = x + w//2 - width//2
        y = y + h//2 - width//2
        face_image = frame[y:y+width, x:x+width].copy()
        cv2.rectangle(frame,(x,y),(x+width,y+width),(255,0,0),2)

        face_image = cv2.resize(face_image,dsize=(FACE_WIDTH, FACE_WIDTH),interpolation=cv2.INTER_AREA)

    frame[0:FACE_WIDTH, 0:FACE_WIDTH] = face_image[:] # 좌측 상단에 출력
    return True

c = PiCam(show=True)
c.run(detect_face)
Beispiel #5
0
class WebManager(WebStructure.WebAbstract):
	def __init__(self,webconf):
		self.webconf=webconf
		self._picam = PiCam()
                config = ConfigParser.ConfigParser()
                config.readfp(open('/etc/raspadmin/picam.conf'))
		self._servoX=config.get("PICAM", "useServoXaxis")
		if self._servoX=="1":
			self._useGPIOPower       = config.get("PICAM", "useGpioPowerSwitch")
			self._servoPwNum         = int(config.get("PICAM","servoControlPinNumber"))
			self._maxServoPulse      = int(config.get("PICAM","maxServoPulse"))
			self._minServoPulse      = int(config.get("PICAM","minServoPulse"))
			self._defaultServoPulse  = int(config.get("PICAM","defaultServoPulse"))
			self._stepServoPulse     = int(config.get("PICAM","stepServoPulse"))
			self._servo = ServoManager(self._servoPwNum,self._minServoPulse, self._maxServoPulse, self._defaultServoPulse,self._stepServoPulse)
			if self._useGPIOPower == "1":
				self._switchGPIONum=int(config.get("PICAM", "switchPinNumber"))
				self._servo.setSwitchMode(self._switchGPIONum)
			
			self._servo.start()

	def get_image(self):
		my_stream = io.BytesIO()
		self._picam.getPicture(my_stream)
		return {'image':base64.b64encode(my_stream.getvalue())}

	def noError(self):
		return WebStructure.HttpContext(statuscode=200,content=json.dumps({'error':0,'errorstr':'No Error'}),template=None,mimetype='text/html')

	def webService(self,post):
		if not 'alphanum_action' in post.keys():
			return WebStructure.HttpContext(statuscode=200,content=None,template=None,mimetype='text/html')
		action=post['alphanum_action']

		if action=='light_inc':
			self._picam.increaseBrightNess()
			return self.noError()
		elif action=='light_dec':
			self._picam.decreaseBrightNess()
			return self.noError()
		elif action=='exposure_inc':
			self._picam.increaseEvCp()
			return self.noError()
		elif action=='exposure_dec':
                        self._picam.decreaseEvCp()
			return self.noError()
		elif action=='movex_inc' and self._servoX=="1":
			self._servo.inc()
			return self.noError()
		elif action=='movex_dec' and self._servoX=="1":
			self._servo.dec()
			return self.noError()

		return WebStructure.HttpContext(statuscode=200,content=None,template=None,mimetype='text/html')


	def get_html(self,http_context):
		template=['header.tpl','picam/picam.tpl','footer.tpl']
		sessionid=http_context.sessionid
		sessionvars=http_context.session.get_vars(sessionid)
                post=http_context.http_post

		if http_context.suburl=='getimage' and self._picam.isActive():
			content=json.dumps(self.get_image())
			return WebStructure.HttpContext(statuscode=200,content=content,template=None,mimetype='text/html')
		elif http_context.suburl=='ws':
			return self.webService(post)
		elif http_context.suburl=='start':
			self._picam.start()
		elif http_context.suburl=='stop':
			self._picam.stop()	
		content={'isActive':self._picam.isActive(),'token':sessionvars['posttoken'],'manageServoX':self._servoX,'gpioSwitch':self._useGPIOPower}	
		return WebStructure.HttpContext(statuscode=200,content=content,template=template,mimetype='text/html')

        def get_module_name(self):
                return "PiCam"
Beispiel #6
0
# import the necessary packages
from picam import PiCam
from time import sleep
import numpy as np
import cv2 as cv

res = (320, 240)
fps = 24

# initialize the camera
#camera = PiCam(res, fps, brightness=55, contrast=10)
#camera = PiCam(res, fps, awb_mode='shade')
camera = PiCam(res, fps, exposure_mode='night')

print('= eff =')
camera.effects()
print('= awb =')
camera.awbModes()
print('= exp =')
camera.exposureModes()

camera.videoCapture()

# allow the camera to warmup
sleep(2.0)

# capture frames from the camera
while True:
    frame = camera.current_frame
    cv.imshow('grid', frame)  # show grid