123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/usr/bin/env python
- #version:2023.04.06
- #显示摄像头图像
- 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/SourceHanSansCN-Regular.otf")
- 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=(240, 320))
- while True:
- buttonDetect()
- savePathHead="/root/user/img/photo_"
- savePathTail=".png"
- 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, 240, 320) #截取图像
- img_backdrop.draw_image(camera_img_capture.rotate(90,adjust=1))
- 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, 240, 320) #截取图像
- camera_img_rotate=camera_img_capture.rotate(90,adjust=1)
- camera_img_rotate.save(savePathHead+timeStampConvert()+savePathTail)
- img_backdrop.draw_image(camera_img_rotate.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)
-
|