当前位置:网站首页>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())
边栏推荐
- 如何安装ps的滤镜插件
- 企业微信和视频号的关联
- 3.2-随机数
- Complete MySQL interview questions (updated in succession)
- 3D point cloud processing series - ---- PCA
- Use of multithreading
- Mmdetection3d (3) -- network output
- @Detailed explanation of requestmapping
- Analysis of Alibaba cloud Tianchi competition questions (in-depth learning) -- Reading Notes 1 -- competition question 1
- Point cloud processing -- binary tree
猜你喜欢

2022 idea (student email authentication) installation and use tutorial and basic configuration tutorial

leetcode系统性刷题(一)-----链表、栈、队列、堆

xcode打包ipa配置手动配置证书

TensorFlow2.0(十一)--理解LSTM网络

概率函数P(x)、概率分布函数F(x)与概率密度函数f(x)的区别

Openpcd installation process record

数字滤波器(三)--模拟滤波器的设计
![[p5.js learning notes] basic knowledge of code drawing](/img/22/30218278b4663e13bf73b25b3bd66f.png)
[p5.js learning notes] basic knowledge of code drawing

Use of multithreading

centos8按照docker官网创wordpress+mysql报错解决
随机推荐
怎样将IDEA与码云进行绑定
MySQL与IDEA连接
Leetcode systematic question brushing (4) -- hash table and string
centos8按照docker官网创wordpress+mysql报错解决
Branch and loop (for and do while)
webview里面$(document).width()都是一个值
[C language must see] yo, writing bugs, I'm sure you've stepped on the pit
C# WPF 正常的项目突然提示 当前上下文中不存在名称“InitializeComponent”
1.2-进制转换
3.2- random numbers
OpenMV(五)--STM32实现人脸识别
leetcode系统性刷题(五)-----动态规划
概率函数P(x)、概率分布函数F(x)与概率密度函数f(x)的区别
Understanding of virtual (virtual method) in C and its difference from abstract (abstract method)
数字滤波器(六)--设计FIR滤波器
OpenMV(二)--IDE安装与固件下载
C#中virtual(虚方法)的理解以及和abstract(抽象方法)的区别
域名解析问题记录
Electrotechnics Volume II self study notes 1.23
OpenMV(六)--STM32实现物体识别与手写数字识别