logo

循环拍照并保存怎么保存不同的名字?

2022-11-03 20:03
M
g23b

循环拍照并保存怎么保存不同的名字?

import sensor, image, time, time, pyb
from pyb import UART
import json

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)                # must be turned off for color tracking
sensor.set_auto_whitebal(False)            # must be turned off for color tracking
clock = time.clock()
uart = UART(3, 115200)

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.8)
    for r in img.find_rects(threshold=3500):     #find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2).find_rects([roi=Auto, threshold=3500])
        area = (r.rect())       #(c.x()-c.r(), c.y()-c.r(), 2*c.r(), 2*c.r())                  #area为识别到的圆的区域,即圆的外接矩形框
        statistics = img.get_statistics(roi=area)                            #像素颜色统计
        print(statistics)
        #(0,100,0,120,0,120)是红色的阈值,所以当区域内的众数(也就是最多的颜色),范围在这个阈值内,就说明是红色的圆。
        #l_mode(),a_mode(),b_mode()是L通道,A通道,B通道的众数。
        if 0<statistics.l_mode()<100 and 0<statistics.a_mode()<120 and 0<statistics.b_mode()<120:      #if the circle is red
            img.draw_rectangle(area,color=(255, 0, 0))
            print("I am find ")                                               #(c.x(), c.y(), c.r(), color = (255, 0, 0))        #识别到的红色区域用红色的圆框出来
            r=200
            uart.write(str(r))                                                                 #200回传到飞控  再m35模式里设置飞机悬停 也就是锁定xyz轴等待几秒运行下图拍照。
            
            time.sleep_ms(10000)


            RED_LED_PIN = 1
            BLUE_LED_PIN = 3

            pyb.LED(RED_LED_PIN).on()
            time.sleep_ms(2000)                              # 给用户一个时间来准备
            pyb.LED(RED_LED_PIN).off()
            time.sleep_ms(2000)

            pyb.LED(BLUE_LED_PIN).on()
            print("You're on camera!")
            img = sensor.snapshot()

            if  n=1 n<4:
                n=n+0
                print(n)

                img.morph(1, [+2, +1, +0,\
                              +1, +1, -1,\
                              +0, -1, -2])                        # 浮雕图像
                img.save("%d.jpg"%n)                              # or "example.bmp" (or others)
                pyb.LED(BLUE_LED_PIN).off()
                print("Done! Reset the camera to see the saved image.")
            else:
                print("Don't find")
        else:
            print("Don't find image.")
M
g23b

我这个只能保存命名为1的图片,我想保存3张分别命名为1,2 ,3

2022-11-03 21:28
I
网红小智智 星瞳科技

你的语法有毛病。

            for n in range(1, 5):
                print(n)

                img.morph(1, [+2, +1, +0,\
                              +1, +1, -1,\
                              +0, -1, -2])                        # 浮雕图像
                img.save("%d.jpg"%n)                              # or "example.bmp" (or others)
                pyb.LED(BLUE_LED_PIN).off()
                print("Done! Reset the camera to see the saved image.")
2022-11-04 16:40
M
g23b

@kidswong999 语法解决啦,但是该如何第一次识别到拍照一次保存命名为1的照片识别第二次保存命名为2的照片 ,我的是识别后直接拍三张

2022-11-04 19:34
I
网红小智智 星瞳科技

@g23b https://forum.singtown.com/topic/9414/%E6%80%8E%E6%A0%B7%E4%BF%9D%E5%AD%98%E5%A4%9A%E5%BC%A0%E6%8B%8D%E6%91%84%E7%9A%84%E7%85%A7%E7%89%87%E5%88%B0sd%E5%8D%A1/4