1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/env python
- #version : 2024.03.14
- #language : en
- #camera : CR5205
- from maix import camera
- from maix import display
- from maix import image #引入python模块包
- import time
- import sys
- sys.path.append('/root/')
- from CocoPi import BUTTON
- image.load_freetype("/root/preset/fonts/CascadiaCodePL-Italic.ttf")
- buttonState=0
- newState=0
- oldState=0
- def buttonDetect():
- global buttonState,newState,oldState
- newState=key_C.is_pressed()
- if newState == True and oldState == False:
- buttonState=1
- elif newState == False and oldState == True:
- buttonState=2
- else:
- buttonState=0
- oldState=newState
-
- def timeStampConvert():
- timeListOutput=""
- timeListOutput = str(time.localtime().tm_year) + \
- str(time.localtime().tm_mon)+str(time.localtime().tm_mday) + \
- str(time.localtime().tm_hour)+str(time.localtime().tm_min) + \
- str(time.localtime().tm_sec)
- return timeListOutput
- key_C = BUTTON(13)
- camera.camera.config(size=(320, 240))
- while True:
- buttonDetect()
- savePathHead="/root/user/img/photo_"
- savePathTail=".jpg"
- if buttonState!=2:
- img_backdrop = image.new(size=(320,240),color=(0, 0, 0)) #创建背景画布
- camera_img = camera.capture() #从摄像头中获取一张图像
- #camera_img_capture = camera_img.crop(0, 0, 320, 240) #截取图像
- img_backdrop.draw_image(camera_img)
- img_backdrop.draw_image((image.open("/root/preset/img/camera_bfbfbf_24x24.png")).rotate(0, adjust=0),292,2,alpha=1)
- img_backdrop.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
- display.show(img_backdrop) #将图像显示出来
- else:
- img_backdrop = image.new(size=(320,240),color=(0, 0, 0)) #创建背景画布
- camera_img = camera.capture() #从摄像头中获取一张图像
- camera_img_capture = camera_img.crop(0, 0, 320, 240) #截取图像
- # camera_img_rotate=camera_img_capture.rotate(90,adjust=1)
- camera_img_capture.save(savePathHead+timeStampConvert()+savePathTail)
- img_backdrop.draw_image(camera_img_capture.resize(280, 210),20,15)
- img_backdrop.draw_image((image.open("/root/preset/img/camera_bfbfbf_24x24.png")).rotate(0, adjust=0),292,2,alpha=1)
- img_backdrop.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
- display.show(img_backdrop) #将图像显示出来
- time.sleep(0.5)
-
|