当前位置:   article > 正文

MicroPython 控制ESP32_CAM摄像头常用API函数_micropython获得图像像素值

micropython获得图像像素值

1.示例

  1. import camera
  2. import struct
  3. import time
  4. ####分辨率范围####
  5. # FRAME_96X96 - 96x96 像素
  6. # FRAME_QQVGA - 160x120 像素 (QQVGA代表Quarter Quarter VGA)
  7. # FRAME_QCIF - 176x144 像素 (QCIF代表Quarter CIF)
  8. # FRAME_HQVGA - 240x160 像素 (HQVGA代表Half Quarter VGA)
  9. # FRAME_240X240 - 240x240 像素
  10. # FRAME_QVGA - 320x240 像素 (QVGA代表Quarter VGA)
  11. # FRAME_CIF - 352x288 像素 (CIF代表Common Intermediate Format)
  12. # FRAME_HVGA - 480x320 像素 (HVGA代表Half VGA)
  13. # FRAME_VGA - 640x480 像素 (VGA代表Video Graphics Array)
  14. # FRAME_SVGA - 800x600 像素 (SVGA代表Super VGA)
  15. # FRAME_XGA - 1024x768 像素 (XGA代表Extended Graphics Array)
  16. # FRAME_HD - 1280x720 像素 (HD代表High Definition)
  17. # FRAME_SXGA - 1280x1024 像素 (SXGA代表Super XGA)
  18. # FRAME_UXGA - 1600x1200 像素 (UXGA代表Ultra XGA)
  19. # FRAME_FHD - 1920x1080 像素 (FHD代表Full High Definition)
  20. # FRAME_P_HD - 1600x1200 像素 (P_HD代表Partial High Definition)
  21. # FRAME_P_3MP - 2048x1536 像素 (P_3MP代表Partial 3 Megapixels)
  22. # FRAME_QXGA - 2048x1536 像素 (QXGA代表Quad Extended Graphics Array)
  23. # FRAME_QHD - 2560x1440 像素 (QHD代表Quad High Definition)
  24. # FRAME_WQXGA - 2560x1600 像素 (WQXGA代表Wide Quad Extended Graphics Array)
  25. # FRAME_P_FHD - 2560x1600 像素 (P_FHD代表Partial Full High Definition)
  26. # FRAME_QSXGA - 2560x2048 像素 (QSXGA代表Quad Super XGA)
  27. if __name__ != '_main_':
  28. try:
  29. camera.init(0, format=camera.JPEG,framesize=camera.FRAME_XGA)
  30. except Exception as e:
  31. camera.deinit()
  32. camera.init(0, format=camera.JPEG,framesize=camera.FRAME_XGA)
  33. time.sleep_ms(500)
  34. ## Other settings:
  35. # flip up side down
  36. camera.flip(1)
  37. # left / right
  38. camera.mirror(1)
  39. time.sleep_ms(200)
  40. # framesize
  41. #camera.framesize(camera.FRAME_240X240)
  42. # The options are the following:
  43. # FRAME_96X96 FRAME_QQVGA FRAME_QCIF FRAME_HQVGA FRAME_240X240
  44. # FRAME_QVGA FRAME_CIF FRAME_HVGA FRAME_VGA FRAME_SVGA
  45. # FRAME_XGA FRAME_HD FRAME_SXGA FRAME_UXGA FRAME_FHD
  46. # FRAME_P_HD FRAME_P_3MP FRAME_QXGA FRAME_QHD FRAME_WQXGA
  47. # FRAME_P_FHD FRAME_QSXGA
  48. # Check this link for more information: https://bit.ly/2YOzizz
  49. # special effects
  50. camera.speffect(camera.EFFECT_NONE)
  51. # The options are the following:
  52. # EFFECT_NONE (default) EFFECT_NEG EFFECT_BW EFFECT_RED EFFECT_GREEN EFFECT_BLUE EFFECT_RETRO
  53. # white balance
  54. camera.whitebalance(camera.WB_NONE)
  55. # The options are the following:
  56. # WB_NONE (default) WB_SUNNY WB_CLOUDY WB_OFFICE WB_HOME
  57. # saturation
  58. camera.saturation(0)
  59. # -2,2 (default 0). -2 grayscale
  60. # brightness
  61. camera.brightness(0)
  62. # -2,2 (default 0). 2 brightness
  63. # contrast
  64. camera.contrast(0)
  65. #-2,2 (default 0). 2 highcontrast
  66. # quality
  67. camera.quality(10)
  68. # 10-63 lower number means higher quality
  69. print("摄像头初始化完成。")
  70. # 获取图像数据流示例
  71. # buffer = camera.capture() #图像数据

2.常用API函数

以下是摄像头控制的一些常见 API 函数、中文名称和使用方式的简要列表:

函数名称使用方式
camera.init()初始化摄像头

camera.init(0, format=camera.JPEG)

    # JPEG -- 3
    # YUV422 -- 1
    # GRAYSCALE -- 2
    # RGB565 -- 0

camera.deinit()关闭摄像头camera.deinit()
camera.framesize()设置摄像头分辨率

camera.framesize(camera.FRAME_240X240)

 # FRAME_96X96 - 96x96 像素

 # FRAME_QQVGA - 160x120 像素 (QQVGA代表Quarter Quarter VGA)

 # FRAME_QCIF - 176x144 像素 (QCIF代表Quarter CIF)

 # FRAME_HQVGA - 240x160 像素 (HQVGA代表Half Quarter VGA)

 # FRAME_240X240 - 240x240 像素

 # FRAME_QVGA - 320x240 像素 (QVGA代表Quarter VGA)

 # FRAME_CIF - 352x288 像素 (CIF代表Common Intermediate Format)

 # FRAME_HVGA - 480x320 像素 (HVGA代表Half VGA)

 # FRAME_VGA - 640x480 像素 (VGA代表Video Graphics Array)

 # FRAME_SVGA - 800x600 像素 (SVGA代表Super VGA)

 # FRAME_XGA - 1024x768 像素 (XGA代表Extended Graphics Array)

 # FRAME_HD - 1280x720 像素 (HD代表High Definition)

 # FRAME_SXGA - 1280x1024 像素 (SXGA代表Super XGA)

 # FRAME_UXGA - 1600x1200 像素 (UXGA代表Ultra XGA)

 # FRAME_FHD - 1920x1080 像素 (FHD代表Full High Definition)

 # FRAME_P_HD - 1600x1200 像素 (P_HD代表Partial High Definition)

 # FRAME_P_3MP - 2048x1536 像素 (P_3MP代表Partial 3 Megapixels)

 # FRAME_QXGA - 2048x1536 像素 (QXGA代表Quad Extended Graphics Array)

 # FRAME_QHD - 2560x1440 像素 (QHD代表Quad High Definition)

 # FRAME_WQXGA - 2560x1600 像素 (WQXGA代表Wide Quad Extended Graphics Array)

 # FRAME_P_FHD - 2560x1600 像素 (P_FHD代表Partial Full High Definition)

 # FRAME_QSXGA - 2560x2048 像素 (QSXGA代表Quad Super XGA)

camera.capture()拍摄照片并保存buffer = camera.capture() #获取图像数据
camera.brightness()设置摄像头亮度

camera.brightness(0)

    # -2,2 (default 0)

camera.contrast()设置摄像头对比度

camera.contrast(0)

    # -2,2 (default 0)

camera.whitebalance()设置摄像头白平衡

camera.whitebalance(camera.WB_NONE)

 # WB_NONE -- 0
 # WB_SUNNY -- 1
 # WB_CLOUDY -- 2
 # WB_OFFICE -- 3
 # WB_HOME -- 4

camera.saturation()设置摄像头饱和度

camera.saturation(0)

    # -2,2 (default 0)

camera.speffect()设置摄像头滤镜

camera.binning(camera.EFFECT_NONE)

 # EFFECT_NONE -- 0
 # EFFECT_NEG -- 1
 # EFFECT_BW -- 2
 # EFFECT_RED -- 3
 # EFFECT_GREEN -- 4
 # EFFECT_BLUE -- 5
 # EFFECT_RETRO -- 6

camera.mirror()设置摄像头镜像效果

camera.mirror(1)

    # 0,1

camera.flip()设置摄像头旋转

camera.flip(1)

    # 0,1


camera.quality()
摄像质量

camera.quality(10)

    # 10-63 数字越低意味着质量越高


        这只是一些常见的摄像头控制 API 函数示例,实际的摄像头库可能具有更多其他功能和选项。确保查阅摄像头库的官方文档以获取更详细的信息和使用方式。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/216307
推荐阅读
相关标签
  

闽ICP备14008679号