'''
实验名称:摄像头使用
实验平台:01Studio CanMV K230
说明:实现摄像头图像采集显示
'''
import time, os, sys,image
from media.sensor import * #导入sensor模块,使用摄像头相关接口
from media.display import * #导入display模块,使用display相关接口
from media.media import * #导入media模块,使用meida相关接口
sensor = Sensor() #构建摄像头对象 标配70°,可选140°
sensor.reset() #复位和初始化摄像头
sensor.set_framesize(Sensor.SVGA) #设置帧大小FHD(1920x1080),默认通道0
sensor.set_pixformat(Sensor.GRAYSCALE) #设置输出图像格式,默认通道0 RGB565
#使用IDE缓冲区输出图像,显示尺寸和sensor配置一致。
Display.init(Display.VIRT, sensor.width(), sensor.height())
MediaManager.init() #初始化media资源管理器
sensor.run() #启动sensor
clock = time.clock()
template = image.Image("/data/template1.jpg")
while True:
################
## 这里编写代码 ##
################
clock.tick()
img = sensor.snapshot() #拍摄一张图
r = img.find_template(template, 0.70, step=10, search=image.SEARCH_EX) # , roi=(10, 0, 60, 60))
if r:
img.draw_rectangle(r)
img.draw_string(0, 0, "FPS:%.2f"%(clock.fps()))
#img.find_hog()
Display.show_image(img) #显示图片
print(clock.fps()) #打印FPS
系统提示:
Traceback (most recent call last):
File “”, line 36, in
OSError: Image is not grayscale!
MPY: soft reboot
CanMV v1.2.2(based on Micropython e00a144) on 2024-12-18; k230_canmv_01studio with K230
我的模板
如果模版改成pgm格式,则报错:
Out of fast frame buffer stack memory