bug in b_or

General discussion about topics related to OpenMV.
OutoftheBOTS
Posts: 87
Joined: Tue May 29, 2018 4:15 am

bug in b_or

Postby OutoftheBOTS » Tue Jun 05, 2018 4:04 am

There seems to be a bug in the b_or see my short explanation video https://youtu.be/qMNy7C22hzY
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Tue Jun 05, 2018 12:08 pm

Yep, looks like a bug. Can you give me your code and I'll fix it tonight.
Nyamekye,
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Tue Jun 05, 2018 12:20 pm

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.
Nyamekye,
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Tue Jun 05, 2018 4:39 pm

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.
Nyamekye,
OutoftheBOTS
Posts: 87
Joined: Tue May 29, 2018 4:15 am

Re: bug in b_or

Postby OutoftheBOTS » Tue Jun 05, 2018 5:25 pm

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

Code: Select all

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())
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Tue Jun 05, 2018 6:03 pm

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.
Nyamekye,
OutoftheBOTS
Posts: 87
Joined: Tue May 29, 2018 4:15 am

Re: bug in b_or

Postby OutoftheBOTS » Tue Jun 05, 2018 6:11 pm

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
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Wed Jun 06, 2018 12:04 am

Question, you do know binary can take multiple colors to threshold at the same time right?
Nyamekye,
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Wed Jun 06, 2018 12:06 am

Ah, I see why this is broken. There's no support in the code that handles line buffers yet for bitmaps. Adding that now...
Nyamekye,
OutoftheBOTS
Posts: 87
Joined: Tue May 29, 2018 4:15 am

Re: bug in b_or

Postby OutoftheBOTS » Wed Jun 06, 2018 12:26 am

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??
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Wed Jun 06, 2018 12:47 am

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
Nyamekye,
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: bug in b_or

Postby kwagyeman » Wed Jun 06, 2018 12:53 am

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.
Attachments
firmware.zip
(1.74 MiB) Downloaded 10 times
Nyamekye,
OutoftheBOTS
Posts: 87
Joined: Tue May 29, 2018 4:15 am

Re: bug in b_or

Postby OutoftheBOTS » Wed Jun 06, 2018 1:27 am

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

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 4 guests