Counting flowers

Ok, so just make a small movie and then return the amount of flowers.

There are 3 parameters in this line :

blobs = img.find_blobs([(90, 100)], merge=True, margin=-10)

Can you explain the 90 and 100 ?
Because how i read it it is area and pixels.
So when i want to detect only blobs that are bigger than 300 pixels i do this ?

blobs = img.find_blobs([(90, 300)], merge=True, margin=-10)

Only it doesn’t work.

90 and100 are the grayscale color thresholds applied to an RGb565 image. So, they are LAB thresholds on the L channel of the image which ranges from 0 to 100. Since the image is binarized only pixels of 0 and 100 in the LAB color space are in it.

You need to add a new parameter area= and pixels= to find_blobs().

90 and100 are the grayscale color thresholds applied to an RGb565 image. So, they are LAB thresholds on the L channel of the image which ranges from 0 to 100. Since the image is binarized only pixels of 0 and 100 in the LAB color space are in it.

You need to add a new parameter area= and pixels= to find_blobs().

Ok that’s make sense.

Only what do we here ?

img.binary([(0, 100, -2, 127, 6, 127)])

I’m was thinking these are the coler tresholds to detect the blobs ??

So now we are detecting blobs in greyscale, so is the global shutter cam better for this aplication ?

I’m binarizing the image first, then apply the erode and dilate filters, and then finding the blobs.

This is two threshold steps. The second step isn’t really needed… but, find_blobs() always thresholds things so I’m just passing it a list of thresholds that select an already thresholded image.

Ok, thank you for this short course openmv.

Just one simple question.
We checking plants on a conveyor belt so we trigger the cam with a plc trough modbus.
This works ok when we are connected with the pc software.
Only when we disconnected the pc software the cam reaction is different.
How is this possible ?
Is this a speed change ?
Can we give the cam a fix FPS ?

When connected to the PC the camera has the load of streaming images to the PC. When not connected it’s not loaded anymore.

You can give a fixed FPS by rate limiting the script using the pyb module:

import pyb

start_ms = pyb.millis()

while True:
    if (pyb.mills() - start) < 50: pyb.delay(1)
    start += 50

This above will limit you to 1000/50 = 20 Hz

I think there are some mistakes in this lines ?

import pyb

start_ms = pyb.millis()

while True:
if (pyb.mills() - start) < 50: pyb.delay(1)
start += 50

This give errors.
When i do this:

import pyb

start = pyb.millis()

while True:
if (pyb.millis() - start) < 50: pyb.delay(1)
start += 50

There are no errors only there is nothing happened.

Yeah, I miss named the variable. But, do you see the idea of what the code is doing?

Yess i see where you want to go , only it doesn’t do anything.

import sensor, image, time
from pyb import UART
import pyb
from modbus import ModbusRTU
uart = UART(3,115200, parity=None, stop=2, timeout=1, timeout_char=4)
modbus = ModbusRTU(uart, register_num=9999, slave_id=0x03)





sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


start = pyb.millis()




while(True):

    clock.tick()
    if (pyb.millis() - start) < 50: pyb.delay(1)
    start += 50
    
    if modbus.any():
        modbus.handle()#debug=True)
    if (modbus.REGISTER [0] == 1):


       img = sensor.snapshot()
       modbus.REGISTER[0] = 0
       img.binary([(50, 100, -10, 127, 20, 127)])
       img.dilate(7, threshold=19)
       img.erode(2, threshold=19)

       blobs = img.find_blobs([(90, 100)],pixels_threshold=180 , merge=False)

       for b in blobs:
           img.draw_rectangle(b.rect(), color=(255, 0, 0))
           modbus.REGISTER[1] = (len(blobs))
           print(len(blobs))
           #print (modbus.REGISTER[0])
           #print (modbus.REGISTER[1])
           print(clock.fps())
import pyb, time

start_ms = pyb.millis()

clock = time.clock()
while True:
    clock.tick()
    while pyb.elapsed_millis(start_ms) < 50: pyb.delay(1)
    start_ms += 50
    print(clock.fps())

if should have been while.

That’s looking more understanding. :smiley:

Thank you alot.