bug in b_or

There seems to be a bug in the b_or see my short explanation video - YouTube

Yep, looks like a bug. Can you give me your code and I’ll fix it tonight.

This works like normal with grayscale and rgb565 image buffers right? Only after you to_bitmap() it does it fail?

Implemented all the binary ops by doing 32 bits at a time… So, something maybe going wrong there.

Question, why do you need to use bitmask for you app? You are finding texts right… And then you want to get the color within each rect? There’s a get_stats() method for that.

For this project I am recreating a Rubik’s Cube solving robot that I built with OpenCV. I need to be able to read the colours of the tiles on the Rubik’s cube. I do this by thresholding each colour to remove all other data but that colour then I join all binary images together using or to give me 1 binary image of just the colours that I am looking for then I look for all squares then find the that r in a 3x3 block and that will be my cube.

I use binary images for a lot of my computer vision project in OpenCV because of 2 reasons : 1. they are super fast to process, 2. thresholding removes unwanted data making it easier to find what I am looking for.

Here’s my current code, I still have to add the other 2 colours yet. If I remove sending the frame buffer to the IDE then it runs at 21fps

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster (160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

green_threshold = (7, 52, -128, -7, -128, 127)
white_threshold = (57, 83, -30, 85, -27, 48)
yellow_threshold = (46, 82, -30, 31, 28, 67)
blue_threshold = (4, 33, -37, 29, -59, -5)

while True:
    clock.tick()
    img = sensor.snapshot()
    blue_fb = img.binary([blue_threshold], to_bitmap=True, copy=True)
    blue_fb.erode(1)
    white_fb = img.binary([white_threshold], to_bitmap=True, copy=True)
    white_fb.erode(1)
    green_fb = img.binary([green_threshold], to_bitmap=True, copy=True)
    green_fb.erode(1)
    yellow_fb = img.binary([yellow_threshold], to_bitmap=True, copy=True)
    yellow_fb.erode(1)
    yellow_fb.b_or(green_fb).b_or(white_fb).b_or(blue_fb)

    print(yellow_fb.compressed_for_ide(), end="")

    print("FPS %f" % clock.fps())

Okay, I see what you are trying to do. I was thinking of just doing find rects and then just test the color inside of the rect. However, this will be slower due to find rects having a frame rate limit.

Sorry about this stuff all being… problematic. Since we have limited ram we were trying to avoid having multiple images in memory ever. One of our design goals was to actually just have one FB with no other images floating around. However, meeting customers requests has… I guess broken that design goal. Anyway, I’ll get b_or fixed tonight.

Thanks for spending so much of your time helping me with my requests.

Another great thing about binary images is they use so little memory you can afford to have many of them even in a constrained environment like a MCU

Question, you do know binary can take multiple colors to threshold at the same time right?

Ah, I see why this is broken. There’s no support in the code that handles line buffers yet for bitmaps. Adding that now…

Question, you do know binary can take multiple colors to threshold at the same time right?

No I didn’t but I do now. What’s the syntax to do this??

img.binary([blue_threshold, white_threshold, green_threshold, yellow_threshold], to_bitmap=True, copy=True)

It says it takes up to 16 thresholds in the documentation. :0

Its fixed. bitmap images may be used with all methods that take two images/scalars now. That said, file loading and unloading is not supported for bitmaps yet. That’s a lot harder to do so it’s not coming soon either.
firmware.zip (1.74 MB)

Thanks. I just installed new firmware and it worked perfectly :slight_smile: