# DAY 1
## 準備咱的材料
1. 樹梅派 x1 (已灌好樹梅派桌面系統)
2. 相機模組 x1 (型號:sc2601)
3. 6mm CCTV鏡頭 x1 (跟相機模組一起買的)

## 下載python套件
```
pip3 install pygame
```
```
pip3 install opencv-python
```
## 測試鏡頭o不ok
用pygame的camera套件來測試,之後會用pygame開發相機介面。
測試鏡頭的code是pygame教學裡的code拼湊起來。
``` python =
import pygame
import pygame.camera
from pygame.locals import *
pygame.init() # 初始化pygame
pygame.camera.init() # 初始化相機模組
class Capture(object):
def __init__(self):
self.size = (640,480) # 大小為 640 x 480
# create a display surface. standard pygame stuff
self.display = pygame.display.set_mode(self.size, 0) # 設置視窗大小
# this is the same as what we saw before
self.clist = pygame.camera.list_cameras() # 搜尋可使用的相機裝置並且放入list
if not self.clist: # 搜尋不到可使用的相機裝時
raise ValueError("Sorry, no cameras detected.")
self.cam = pygame.camera.Camera(self.clist[0], self.size) # 設置欲啟用的相機,為相機list的第一個
self.cam.start() # 啟動該相機
# create a surface to capture to. for performance purposes
# bit depth is the same as that of the display surface.
self.snapshot = pygame.surface.Surface(self.size, 0, self.display) # 設置畫布大小,並且把畫布設置在self.display這個視窗上
def get_and_flip(self):
# if you don't want to tie the framerate to the camera, you can check
# if the camera has an image ready. note that while this works
# on most cameras, some will never return true.
if self.cam.query_image():
self.snapshot = self.cam.get_image(self.snapshot)
# blit it to the display surface. simple!
self.display.blit(self.snapshot, (0,0))
pygame.display.flip()
def main(self):
going = True
while going:
events = pygame.event.get()
for e in events:
if e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE):
# close the camera safely
self.cam.stop()
going = False
self.get_and_flip()
a = Capture() # 這變數名稱請見諒,測試用的qq
a.main()
```
{"metaMigratedAt":"2023-06-15T20:14:18.104Z","metaMigratedFrom":"Content","title":"DAY 1","breaks":true,"contributors":"[{\"id\":\"a922406d-85ee-4574-b22f-5a8f450f2de9\",\"add\":2152,\"del\":53}]"}