logo

openmv3 cam7 gpio 控制高低电平 在循环中 硬件lcd 白屏 ,pc 显示图像。后死机

2021-07-22 14:06
C
c5xl
# Find Lines Example
#
# This example shows off how to find lines in the image. For each line object
# found in the image a line object is returned which includes the line's rotation.

# Note: Line detection is done by using the Hough Transform:
# http://en.wikipedia.org/wiki/Hough_transform
# Please read about it above for more information on what `theta` and `rho` are.

# find_lines() finds infinite length lines. Use find_line_segments() to find non-infinite lines.

enable_lens_corr = False # turn on for straighter lines...

import sensor, image, time,lcd,pyb


p = pyb.Pin("P7", pyb.Pin.OUT_PP)

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster
sensor.set_framesize(sensor.QQVGA2)
sensor.skip_frames(time = 2000)
clock = time.clock()
lcd.init()

# All line objects have a `theta()` method to get their rotation angle in degrees.
# You can filter lines based on their rotation angle.

min_degree = 175
max_degree = 185

a=False
b=False


# All lines also have `x1()`, `y1()`, `x2()`, and `y2()` methods to get their end-points
# and a `line()` method to get all the above as one 4 value tuple for `draw_line()`.

while(True):
    lcd.display(sensor.snapshot()) # Take a picture and display the image.
    clock.tick()


    img = sensor.snapshot().gamma_corr(gamma = 0.5, contrast = 0.5, brightness = 0.3)

    img = sensor.snapshot()
    if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens...

    # `threshold` controls how many lines in the image are found. Only lines with
    # edge difference magnitude sums greater than `threshold` are detected...

    # More about `threshold` - each pixel in the image contributes a magnitude value
    # to a line. The sum of all contributions is the magintude for that line. Then
    # when lines are merged their magnitudes are added togheter. Note that `threshold`
    # filters out lines with low magnitudes before merging. To see the magnitude of
    # un-merged lines set `theta_margin` and `rho_margin` to 0...

    # `theta_margin` and `rho_margin` control merging similar lines. If two lines
    # theta and rho value differences are less than the margins then they are merged.





    for l in img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25):
        if (min_degree <= l.theta()) and (l.theta() <= max_degree):
           # img.draw_line(l.line(), color = (255, 0, 0))
            if  l.x1()>55 and   l.x1()<75 :
                img.draw_line(l.line(), color = (255, 0, 0))
                a=True
                #if ( abs (  l.x2()-l.x1() )<=5  ):
                # print(l)
                img.draw_string(70, 10, "ok-A", color = (255,255,255), scale = 2, mono_space = False,char_rotation = 0, char_hmirror = False, char_vflip = False,string_rotation = 0, string_hmirror = False, string_vflip = False)
            # print(l)

        if (85 <= l.theta()) and (l.theta() <= 95):
            if  l.y1()>60 and   l.y1()<90 :
                img.draw_line(l.line(), color = (255, 0, 0))
                b=True
                img.draw_string(80, 60, "ok-B", color = (255,255,255), scale = 2, mono_space = False,char_rotation = 0, char_hmirror = False, char_vflip = False,string_rotation = 0, string_hmirror = False, string_vflip = False)

    img.draw_rectangle(0,60 , 128, 30, color = (255,255,255), thickness = 2, fill = False)
    img.draw_rectangle(55,0 , 20, 160, color = (255,255,255), thickness = 2, fill = False)
    if (a==True):               p.high()
    # or p.value(1) to make the pin high (3.3V)

    lcd.display(img)

    print("FPS %f" % clock.fps())
# About negative rho values:
#
# A [theta+0:-rho] tuple is the same as [theta+180:+rho].
2021-07-22 21:00
I
网红小智智 星瞳科技

LCD扩展板占用了P7引脚,所以不能同时使用。

https://singtown.com/product/636/opeenmv-lcd-shield/