I need input on a possible bug in v3.5.0
#11
@TerryRitchie

Hi
I'm very glad to say you... I have found the bug!

Yes, IMHO if you change one line of your MakeMask routine, your tool works perfectly!
Code: (Select All)
cc~& = Point(10, 10) '_RGB32(255, 0, 255) '                       set the color to be used as transparent
the issue comes out from the setting of the background color in MakeMask routine!
We must take background/ transparent color from the image passed to the routine!
Please take a try and you enjoy to see working your tool for detection!
Thanks to Bplus for rising out this bug! We get another step toward a good tool!
Reply
#12
Hi @TempodiBasic, 

Yeah I tried setting _Clearcolor after loading the images and got no improvements. Terry's code does stuff with "Mask" which required too much study by me. So I will try today and see what I can come up with independent of Terry code trouble is now I have mask stuck in my mind ;-))

It does look like you want x and y radius of object to minimize scanning though pixels. And isolating an object in an image is interesting problem in itself.

PS Oh just saw 2nd post, I will check out!
b = b + ...
Reply
#13
(01-20-2023, 11:25 PM)bplus Wrote: I just tried 2 Xmas Stars with Terry's code, looks like a complicated thing using a mask and requiring image object to fit exactly inside image width and height... I don't know. It didn't allow a simple substitution of images of 2 other objects. Damn might have to read the directions, all is lost ;-))

If Terry wants to try here are 2 images to check with collision code colors are red 255, blue 255 and clear or black background.

Run those images through a color detection routine... I'm getting a ton of colors in them!  (all various shades of black, but colors nonetheless.)  The red star is terrible with it.  Was it converted from a jpg or something??

If I was going to check these 2 images for collision, I'd at least expect the backgrounds to be 0 alpha, to make the blending and checking considerably easier.  Wink
Reply
#14
Got it working as TempodiBasic sorta said but the edge of the image is also colliding with the stationary object.

Changed code to put center of image at mouse not top edge so can move over entire screen.

The collision detection works when star touches star but also goes off as I said when border of mouse image touches stationary star.
Working:
       

Colliding with edge:
   
For some reason that edge of image is not clean ie transparent like the rest of it is.

Here is my code mods in zip pack.


Attached Files
.zip   PixelCollide Mods 2023-01-21.zip (Size: 7.03 KB / Downloads: 25)
b = b + ...
Reply
#15
(01-21-2023, 11:17 AM)TempodiBasic Wrote: @TerryRitchie

Hi
I'm very glad to say you... I have found the bug!

Yes, IMHO if you change one line of your MakeMask routine, your tool works perfectly!
Code: (Select All)
cc~& = Point(10, 10) '_RGB32(255, 0, 255) '                       set the color to be used as transparent
the issue comes out from the setting of the background color in MakeMask routine!
We must take background/ transparent color from the image passed to the routine!
Please take a try and you enjoy to see working your tool for detection!
Thanks to Bplus for rising out this bug! We get another step toward a good tool!

Oh for goodness sake. I hard coded the transparent color for the example images instead having the routine detect the transparent color. Thanks for finding this. The code works for this example but will fail when images with differing transparent colors are used. Your catch will make this a true general use routine.

I'll work on changing the code and upload the result here.
Reply
#16
(01-21-2023, 03:53 PM)TerryRitchie Wrote:
(01-21-2023, 11:17 AM)TempodiBasic Wrote: @TerryRitchie

Hi
I'm very glad to say you... I have found the bug!

Yes, IMHO if you change one line of your MakeMask routine, your tool works perfectly!
Code: (Select All)
cc~& = Point(10, 10) '_RGB32(255, 0, 255) '                       set the color to be used as transparent
the issue comes out from the setting of the background color in MakeMask routine!
We must take background/ transparent color from the image passed to the routine!
Please take a try and you enjoy to see working your tool for detection!
Thanks to Bplus for rising out this bug! We get another step toward a good tool!

Oh for goodness sake. I hard coded the transparent color for the example images instead having the routine detect the transparent color. Thanks for finding this. The code works for this example but will fail when images with differing transparent colors are used. Your catch will make this a true general use routine.

I'll work on changing the code and upload the result here.

Even with that fix there is still a false positive collision detected when the image edge contacts the other image, modified code in zip for testing above.
b = b + ...
Reply
#17
starRed and starBlue collision demo:

Code: (Select All)
SCREEN _NEWIMAGE(1280, 720, 32)
DIM AS _UNSIGNED LONG target
DIM SHARED Backdrop AS LONG: Backdrop = _COPYIMAGE(0)
blueStar = _LOADIMAGE("Z:\starBlue.png", 32)
redStar = _LOADIMAGE("z:\starRed.png", 32)

bs = MBI(blueStar)
rs = MBI(redStar)



DO
    ClearScreens
    k = _KEYHIT
    SELECT CASE k
        CASE 18432: yPos = yPos - 1
        CASE 20480: yPos = yPos + 1
        CASE 19200: xPos = xPos - 1
        CASE 19712: xPos = xPos + 1
        CASE 32: xPos = 0: yPos = 0 'reset
        CASE 27: SYSTEM
    END SELECT
    PlaceImage 100, 100, bs, bs
    PlaceImage xPos, yPos, rs, rs
    IF checkCollision(x&, y&) THEN PRINT "COLLISON AT: "; x&, y&
    _LIMIT 60
    _DISPLAY
LOOP



SUB ClearScreens
    D = _DEST: CLS , 0: _DEST Backdrop: CLS , 0: _DEST D
END SUB


SUB PlaceImage (x AS LONG, y AS LONG, image AS LONG, imagebackdrop AS LONG)
    _PUTIMAGE (x, y), image, _DISPLAY
    _PUTIMAGE (x, y), imagebackdrop, Backdrop
END SUB

FUNCTION checkCollision (x AS LONG, y AS LONG) 'check for our target color
    STATIC m AS _MEM
    m = _MEMIMAGE(Backdrop)
    DIM AS _OFFSET o, l
    DIM AS _UNSIGNED LONG p
    o = m.OFFSET: l = m.OFFSET + m.SIZE
    FOR y = 0 TO _HEIGHT - 1
        FOR x = 0 TO _WIDTH - 1
            _MEMGET m, o, p
            IF p = &HC07F003F THEN
                checkCollision = -1
                EXIT FUNCTION
            END IF
            o = o + 4
        NEXT
    NEXT
END FUNCTION


FUNCTION MBI (image AS LONG) 'make backdrop image
    DIM temp AS LONG: temp = _COPYIMAGE(image)
    DIM m AS _MEM: m = _MEMIMAGE(temp)
    DIM AS _OFFSET o, l
    DIM AS _UNSIGNED LONG p
    o = m.OFFSET: l = m.OFFSET + m.SIZE
    DO UNTIL o >= l
        _MEMGET m, o, p
        SELECT CASE p
            CASE &HFFFF0000: _MEMPUT m, o, &H80FF0000 AS _UNSIGNED LONG
            CASE &HFF0000FF: _MEMPUT m, o, &H800000FF AS _UNSIGNED LONG
            CASE ELSE: _MEMPUT m, o, &H00000000 AS _UNSIGNED LONG
        END SELECT
        o = o + 4
    LOOP
    MBI = temp
END FUNCTION


I tweaked your stars to get rid of the black backgrounds.  See how the above works for you.  Wink
Reply
#18
@SMcNeill
You have a good look...the images show some impurities... So no one background color!
This following image of a red star has been made by Paint of Windows with one color for background and it works very well in the demo of Terry Ritchie for collision detected by mask.

[Image: starRed3.png]


@Bplus + @TerryRitchie

It is because what we see as one black background in the star's image is a not a pure (made by one color) background until the edges as already pointed out by Steve!
I made another RedStarimage.png using Paint of Windows: I loaded RedStar.png , then I select a closer area around the star and I copied it.
Then I made another image, background set to black by fillcolor tool of Paint and pasting the redStar in it.
So it works well!
Reply
#19
@TempodiBasic My solution was simple -- I just filtered out anything that wasn't read or blue and turned them all transparent 0.  Smile
Reply
#20
@Steve SMcNeill
hi boy
very good your MOD  
1 you set one color for background of images
2 you use keyboard to move image, so it is possible to evaluate with more precision the sensibility of detection of collision
3 you speed up the operations of working and comparing the area of graphic images using _MEM functions

one neo
I must cancel  "Z:\" from the path of images to be loaded  :-P
Reply




Users browsing this thread: 16 Guest(s)