本篇繼續來測試 ESP32-WROVER-DEV 開發板的影像擷取, 本系列前一篇測試參考 :
使用的程式碼如下 :
import time, camera
from machine import reset
def init_camera(**config): # 初始化鏡頭
camera.init(
0, d0=4, d1=5, d2=18, d3=19, d4=36, d5=39, d6=34, d7=35,
href=23, vsync=25, reset=-1, sioc=27, siod=26, xclk=21,
pclk=22, fb_location=camera.PSRAM, format=camera.JPEG,
xclk_freq=camera.XCLK_10MHz, framesize=camera.FRAME_QVGA,
**config)
def capture_image(file_name='capture.jpg'): # 拍攝照片並存檔
time.sleep(2) # 等待攝像頭穩定
buf=camera.capture()
if buf:
with open(f'/{file_name}', 'wb') as f:
f.write(buf)
print(f'Image has been saved as {file_name}')
else:
print('Failed to capture image')
camera.deinit()
del buf
先抓一張預設未調整影像 :
>>> init_camera()
True
>>> capture_image(file_name='capture1.jpg')
14487
Image has been saved as capture1.jpg
True
接下來測試 camera 模組的各個函式.
1. 亮度 (brightness) :
>>> init_camera()
True
>>> camera.brightness(2)
>>> capture_image(file_name='capture2.jpg')
9985
Image has been saved as capture2.jpg
True
感覺反而比預設圖暗 (也可能是室內燈光關係). 下面是設成最暗 :
>>> init_camera()
True
>>> camera.brightness(-2)
>>> capture_image(file_name='capture3.jpg')
9388
Image has been saved as capture3.jpg
True
有比預設圖暗.
2. 對比度 (contrast) :
接著用 camera.contrast(2) 將對比度調到最大 :
>>> init_camera()
True
>>> camera.contrast(2)
>>> capture_image(file_name='capture4.jpg')
9422
Image has been saved as capture4.jpg
True
下面是對比最弱 :
>>> init_camera()
True
>>> camera.contrast(-2)
>>> capture_image(file_name='capture5.jpg')
9417
Image has been saved as capture5.jpg
True
跟預設圖似乎差不多, 看不出明顯的對比變化.
3. 飽和度 (saturation) :
參數範圍 [-2, 2] 預設為 0, 負值偏灰, 正值偏彩. 下面是設定飽和度=2 :
>>> init_camera()
True
>>> camera.saturation(2)
>>> capture_image(file_name='capture6.jpg')
9402
Image has been saved as capture6.jpg
True
下面測試飽和度 -2 :
>>> init_camera()
True
>>> camera.saturation(-2)
>>> capture_image(file_name='capture7.jpg')
9339
Image has been saved as capture7.jpg
True
看不出有差異.
4. 對比度 (contrast) :
camera.contrast() 參數範圍 [-2, 2] 預設為 0, 設為 2 對比最高, -2 最低.
>>> init_camera()
True
>>> camera.contrast(2)
>>> capture_image(file_name='capture8.jpg')
9360
Image has been saved as capture8.jpg
True
下面是對比度 -2 效果 :
>>> init_camera()
True
>>> camera.contrast(-2)
>>> capture_image(file_name='capture9.jpg')
9233
Image has been saved as capture9.jpg
True
看不出有何變化.
5. 特效 (speffect) :
camera 有六種特效, 但測試發現並無明顯效果, 下面是負片測試 :
>>> init_camera()
True
>>> camera.speffect(camera.EFFECT_NEG)
>>> capture_image(file_name='capture10.jpg')
9314
Image has been saved as capture10.jpg
True
下面黑白片測試無效 :
>>> init_camera()
True
>>> camera.speffect(camera.EFFECT_BW)
>>> capture_image(file_name='capture11.jpg')
8717
Image has been saved as capture11.jpg
True
下面是紅色濾鏡效果 :
>>> init_camera()
True
>>> camera.speffect(camera.EFFECT_RED)
>>> capture_image(file_name='capture12.jpg')
cam_hal: EV-EOF-OVF
cam_hal: EV-VSYNC-OVF
8751
Image has been saved as capture12.jpg
True
綠色濾鏡特效 :
>>> init_camera()
True
>>> camera.speffect(camera.EFFECT_GREEN)
>>> capture_image(file_name='capture13.jpg')
8719
Image has been saved as capture13.jpg
True
藍色濾鏡效果 :
>>> init_camera()
True
>>> camera.speffect(camera.EFFECT_BLUE)
>>> capture_image(file_name='capture14.jpg')
8650
Image has been saved as capture14.jpg
True
>>> init_camera()
True
>>> camera.speffect(camera.EFFECT_RETRO)
>>> capture_image(file_name='capture15.jpg')
8793
Image has been saved as capture15.jpg
True
這些特效似乎與預設圖沒啥差異.
6. 垂直翻轉 (flip) :
呼叫 flip() 並傳入 1 或 True 可讓擷取之影像垂直翻轉, 但並無效果 :
>>> init_camera()
True
>>> camera.flip(True)
>>> capture_image(file_name='capture16.jpg')
8617
Image has been saved as capture16.jpg
True
7. 水平翻轉 (mirror) :
呼叫 mirror() 並傳入 1 或 True 可讓擷取之影像水平翻轉, 但測試無效果 :
>>> init_camera()
True
>>> camera.mirror(True)
>>> capture_image(file_name='capture17.jpg')
8497
Image has been saved as capture17.jpg
True
8. 畫質 (quality) :
呼叫 quality() 設定影像品質, 參數範圍 [10, 63] 預設為 12, 值越大品質越高, 但測試無效果.
>>> init_camera()
True
>>> camera.quality(30)
>>> capture_image(file_name='capture18.jpg')
cam_hal: EV-EOF-OVF
8545
Image has been saved as capture18.jpg
True
圖檔大小仍是一般 8KB, 解析度仍是 320*240, 畫質其實沒有變化.
以上測試結果顯示, camera 模組雖然可以正常擷取影像, 但它的許多函式目前可能只是一個空殼的介面並未實作, 所以並無效果.
沒有留言 :
張貼留言