当前位置:网站首页>Openmv (III) -- get camera pictures in real time
Openmv (III) -- get camera pictures in real time
2022-07-28 17:57:00 【A bone loving cat】
Get camera pictures in real time
lead
OpenMV( One )– Basic introduction and hardware architecture
OpenMV( Two )–IDE Installation and firmware download
Preface
utilize OpenMV The basis of machine vision development is to analyze the images taken by the camera , Getting the pictures taken by the camera is the first step of the long march . The columns in this series are all OV7725 Roller shutter camera . We will start from OpenMV Start with the corresponding constructor in , Analyze the source code to realize this function .
1. Constructors
OpenMV All functions related to the camera are encapsulated in sensor Module , It's easy to call .
sensor function
- sensor.reset()
Initialize the camera - sensor.set_pixformat(pixformat)
Set pixel format .pixformat There are three parameters :- sensor.GRAYSCAL: Grayscale image , Every pixel 8 position (1 byte ), Fast processing speed
- sensor.RGB565: Each pixel is 16 position ,5 Bit red ,6 Bit green ,5 Bit blue , The processing speed is slower than that of gray image
- sensor.BAYER: Small space , For capturing images only , Can't do image processing
- sensor.set_framesize(framesize)
Set the size of each frame , That is, image size . frequently-used framesize There are several parameters :- sensor.QQVGA: 160*120
- sensor.QVGA: 320*240
- sensor.VGA: 640*480
- sensor.LCD: 128*160 ( For official use LCD modular )
- sensor.QQVGA2: 128*120 ( For official use LCD modular )
- sensor.skip_frames([n, time])
Number of frames ignored or waiting time after camera initialization , Wait for the camera to stabilize .- n: Frames ignored
- time: Waiting time
- sensor.snapshot()
Take a picture with the camera , And back to imag Images
- sensor.reset()
clock function
clock Function can be used to calculate the number of frames per second of the camera- clock = time.clock()
Create a clock - clock.tick()
Start tracking run time - clock.fps()
Stop tracking run time , And return to the current FPS( Frames per second )
- clock = time.clock()
2. Source code analysis
Let's take the official source code of real-time camera image acquisition as an example , Analyze it , The steps of acquiring images in real time are :
Initialize the camera --> Set the format of the collected photos --> Set the size of the collected photos --> Wait for the camera to be set --> Take an image
""" Real time camera image acquisition routine """
# Import the corresponding library
import sensor, image, time
# Initialize the camera
sensor.reset()
# Set the format of the collected photos : colour RGB
sensor.set_pixformat(sensor.RGB565)
# Set the size of the collected photos : 320 * 240
sensor.set_framesize(sensor.QVGA)
# Wait for a while 2s, Wait until the camera is set
sensor.skip_frames(time = 2000)
# Create a clock to calculate the number of frames captured by the camera per second FPS
clock = time.clock()
# Real time display of photos taken by the camera
while(True):
# to update FPS The clock
clock.tick()
# Take a picture and return img
img = sensor.snapshot()
# Serial printing FPS Parameters
print(clock.fps())
We connect the board to OpenMV IDE, New file , And put the above code copy go in , Click the green button in the lower left corner , We can see IDE The window on the right shows the pictures of the camera in real time :
And then we click IDE Lower left corner “ Serial terminal ”, You can find that it is printing the camera FPS:
3. Run program offline
One thing to note is that , Our board is connected to IDE When , The running speed will be reduced , When running offline , We can make small FPS Will rise to 2 Times the speed . About how to run our written program offline ? When our board passes USB When you plug in the computer , It's going to jump out of a U Disk interface , There are three files on it :
among main.py Is the main function code file , Run first after power on . We can put the code directly copy To main.py in , You can realize the offline operation of the program . Of course , If you want to see the effect of displaying images in real time , We need to add one to our board LCD, And change the procedure as follows ( In the official LCD For example ):
""" Real time camera image acquisition routine """
# Import the corresponding library
import sensor, image, lcd
# Initialize the camera
sensor.reset()
# Set the format of the collected photos : colour RGB
sensor.set_pixformat(sensor.RGB565)
# Set the size of the collected photos : 320 * 240
sensor.set_framesize(sensor.QVGA)
# Wait for a while 2s, Wait until the camera is set
sensor.skip_frames(time = 2000)
#LCD initialization
lcd.init()
# Real time display of photos taken by the camera
while(True):
# Take pictures and display images .
lcd.display(sensor.snapshot())
边栏推荐
- centos使用docker运行mysql后,远程连接需要开放端口
- [p5.js actual combat] my self portrait
- @Detailed explanation of requestmapping
- 【Unity】Timeline学习笔记(七):自定义片段(Clip)
- 【p5.js学习笔记】码绘的基础知识
- 【p5.js学习笔记】鼠标交互事件
- com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的配置文件
- 电脑充不进去电的解决方法
- Point cloud processing -- binary tree
- 概率函数P(x)、概率分布函数F(x)与概率密度函数f(x)的区别
猜你喜欢
随机推荐
【p5.js实战】我的自画像
How to install PS filter plug-in
【Unity】Timeline学习笔记(七):自定义片段(Clip)
mmdetection3d(2)---结果、log可视化
封装、继承、多态
三维点云处理系列----PCA
Collection collection
com.mysql.jdbc. Configuration files of driver and com.mysql.cj.jdbc.driver
Branch and loop statements
IO的操作
ROS custom message and use
How to upload a project to the code cloud using idea
Complete MySQL interview questions (updated in succession)
【p5.js】实战临摹——国际象棋盘
Methods, functions
视频号如何将公域流量将用户导入私域
2.1 operator
centos8使用docker安装wordpress+mysql配置文件中WORDPRESS_DB_HOST的理解
Electrotechnics self study notes 1.21
mmdetection3D---(1)









