Results 1 to 4 of 4

Thread: get direction of object movement from bitmap

  1. #1

    Thread Starter
    Member NTShpikho's Avatar
    Join Date
    Oct 2023
    Posts
    38

    get direction of object movement from bitmap

    Code:
        public ImageDepictor directionGetter(Bitmap bmp1)
        {
            ImageDepictor imageDepictor = new ImageDepictor();
            Boolean refreshImageA = false;
            Boolean exploded = resulTemp.contains("explosion");
            Boolean imploded = resulTemp.contains("implosion");
            resulTemp="";
            Boolean[][] imageB = new Boolean[13][13];
            for (int i = 0; i < imageB.length; i++){
                Arrays.fill(imageB[i], false);
            }
            int changeCurMax = -1;
            int changeCurMin =9001;
            int changeCurMaxY = -1;
            int changeCurMinY =9001;
            //preloop vars :
            int jumpX = bmp1.getWidth()/14;
            int jumpY = bmp1.getHeight()/14;
            Boolean outlinePxl = false;
            for (int i = 1; i <= 13; ++i) {
                for (int j = 1; j <= 13; ++j) {
                    //Boolean outlinePxl = isOutLine(j*jumpX,i*jumpY,bmp1,20);
                    int pixel = bmp1.getPixel(j*jumpX,i*jumpY);
                    outlinePxl = isBlackPixel(pixel);
                    if(outlinePxl){bmp1=mark_dark_pixel_red(j*jumpX,i*jumpY,bmp1,(byte)30);imageB[j-1][i-1]=true;}
                    if(imageB[j-1][i-1]^imageA[j-1][i-1]){
                        changeCurMin=miner(j,changeCurMin);changeCurMax=maxer(j,changeCurMax);
                        changeCurMinY=miner(i,changeCurMinY);changeCurMaxY=maxer(i,changeCurMaxY);
                    }
    //                if(!(outlinePxl)){bmp1=mark_dark_pixel_red(j*jumpX,i*jumpY,bmp1,(byte)10);imageB[j][i]=true;
    //                if(!imageA[j][i]){changeCurMin=miner(j,changeCurMin);changeCurMax=maxer(j,changeCurMax);
    //                    changeCurMinY=miner(j,changeCurMinY);changeCurMaxY=maxer(j,changeCurMaxY);
    //                }
    //                }
                }
            }
            Log.i("test", "shiiiiiiiiiiiiiiiit");
            //mark movement area :
            bmp1=mark_dark_pixel(changePrevMin*jumpX,6*jumpY,bmp1,(byte)50);
            bmp1=mark_dark_pixel(changePrevMax*jumpX,6*jumpY,bmp1,(byte)50);
            bmp1=mark_dark_pixel_blue(changeCurMax*jumpX,5*jumpY,bmp1,(byte)50);
            bmp1=mark_dark_pixel_blue(changeCurMin*jumpX,5*jumpY,bmp1,(byte)50);
            imageDepictor.setBmp(bmp1);
            //imageDepictor.setBmp(graphicContour(bmp1,(changeCurMin+1)*jumpX,(changeCurMax+1)*jumpX,(changeCurMinY+1)*jumpY,(changeCurMaxY+1)*jumpY,Color.BLUE));
            if(imploded){
                if(changeCurMax-changePrevMax>changePrevMax-changeCurMin){resulTemp ="right";}
                else{resulTemp="left";}
                bmp1=mark_dark_pixel_black(changePrevMin*jumpX,6*jumpY,bmp1,(byte)50);
                bmp1=mark_dark_pixel_black(changePrevMax*jumpX,6*jumpY,bmp1,(byte)50);
            }else{
            if(changeCurMax>changePrevMax){resulTemp+="right";}
            if(changeCurMin<changePrevMin){resulTemp+="left";}
            if(resulTemp.equals("rightleft")){resulTemp="explosion";}
            if(changeCurMax<changePrevMax&&changeCurMin>changePrevMin){resulTemp="implosion";}
            if(exploded&&changeCurMax<=changePrevMax&&changeCurMin>=changePrevMin){resulTemp="implosion";}
    
            if(!exploded&&changeCurMax==changePrevMax&&changeCurMin==changePrevMin){resulTemp="blink";}
            if(resulTemp.isEmpty()){resulTemp="static";}}
    
                for (int i = 1; i <= 13; ++i) {
                    for (int j = 1; j <= 13; ++j) {
                        imageA[j-1][i-1]=imageB[j-1][i-1];
                    }
            }
            changePrevMax = changeCurMax;
            changePrevMin=changeCurMin;
            changePrevMaxY = changeCurMax;
            changePrevMinY=changeCurMin;
            if(resulTemp.equals("implosion")){
                changePrevMax = changeCurMin + (changeCurMax-changeCurMin)/2;
                changePrevMin=changePrevMax;
    
            }
            imageDepictor.setDepiction(resulTemp);
            return imageDepictor;
        }
    the method says where movement went to, by comparing the bitmap it gets to the prev bitmap it got(in the previous call).

    implosion means the object shrunk(went far or got small in size)
    down that coffee slug

  2. #2
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    543

    Re: get direction of object movement from bitmap

    You just can't post code anywhere. This forum is for Visual Basic .NET.

    There's a separate forum for your Java code:
    https://www.vbforums.com/forumdisplay.php?10-Java

    Most programming langauges have their own forum.
    Last edited by Peter Porter; Dec 11th, 2023 at 09:09 AM.

  3. #3

    Thread Starter
    Member NTShpikho's Avatar
    Join Date
    Oct 2023
    Posts
    38

    Re: get direction of object movement from bitmap

    Quote Originally Posted by Peter Porter View Post
    You just can't post code anywhere. This forum is for Visual Basic .NET.

    There's a separate forum for your Java code:
    https://www.vbforums.com/forumdisplay.php?10-Java

    Most programming languages have their own forum.
    sorry, I got the languages mixed up by mistake.
    down that coffee slug

  4. #4
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    543

    Re: get direction of object movement from bitmap

    Quote Originally Posted by NTShpikho View Post
    sorry, I got the languages mixed up by mistake.
    It's all good now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width