battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionartificial eye - java A.Eye artificial eye fastest image detection algorithm and code Emptyjava A.Eye artificial eye fastest image detection algorithm and code

more_horiz


Code:

package com.yotamarker.eyeresearch;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.drawable.BitmapDrawable;
import android.media.MediaPlayer;
import android.support.constraint.solver.widgets.Rectangle;
import android.util.Log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class AEye {
    private char colorTarget = 'k';

    public char getColorTarget() {
        return colorTarget;
    }

    public void setColorTarget(char colorTarget) {
        this.colorTarget = colorTarget;
    }

    private int minObjectSize = 40; // how small an objext detected can be
    private AEyeClassifier eyeObj = new AEyeClassifier();
    private final int midShiber =1;
    //direction recognition global variables :
    private Boolean[][] imageA = new Boolean[13][13];
    private int changePrevMax =-1;
    private int changePrevMin =9001;
    private int changePrevMaxY =-1;
    private int changePrevMinY =9001;
    private String resulTemp ="";
    //movement after being static :
    private int ppm =0;
    private int ppmin = 0;
    private int ppmY =0;
    private int ppminY = 0;
    public ImageDepictor imageDepictor = new ImageDepictor();
    // end direction recognition global variables
    public AEye() {
        //c'tor
        for (int i = 0; i < imageA.length; i++){
            Arrays.fill(imageA[i], false);
        }
    }

    public void setMinObjectSize(int newVal) {
        // set minimum detectable item size
        if ((newVal >= 13)) {
            minObjectSize = newVal;
        }

    }

    public boolean overlappingRectangles(Rectangle R1, Rectangle R2) {
        // check if 2 rectangles overlap
        if (((R1.x > (R2.x + R2.width)) || ((R1.x + R1.width) < R2.x))) {
            return false;
        }

        if (((R1.y > (R2.y + R2.height)) || ((R1.y + R1.height) < R2.y))) {
            return false;
        }

        return true;
    }
    public Bitmap mark_dark_pixel(int x, int y, Bitmap bmp1, byte marker) {
        /* marker : size of marking around marked pixel (will show as colored square)
        x,y : pixels location
        * */
        for (int i = 0; (i <= marker); i++) {
            for (int j = 0; (j <= marker); j++) {
                try {
                    bmp1.setPixel((x + j), (y + i),Color.GREEN);
                }
                catch (Exception ex) {
                }

            }

        }
        return bmp1;
    }
    public Bitmap mark_dark_pixel(int x, int y, Bitmap bmp1, byte marker, int colorDotEnum) {
        /* marker : size of marking around marked pixel (will show as colored square)
        x,y : pixels location
        colorDotEnum : example : Color.Green
        * */
        for (int i = 0; (i <= marker); i++) {
            for (int j = 0; (j <= marker); j++) {
                try {
                    bmp1.setPixel((x + j), (y + i),colorDotEnum);
                }
                catch (Exception ex) {
                }

            }

        }
        return bmp1;
    }
    public Bitmap mark_dark_pixel_white(int x, int y, Bitmap bmp1, byte marker) {
        /* marker : size of marking around marked pixel (will show as colored square)
        x,y : pixels location
        * */
        return mark_dark_pixel(x,y,bmp1 ,(byte)marker,  Color.WHITE);
    }
    public Bitmap mark_dark_pixel_black(int x, int y, Bitmap bmp1, byte marker) {
        /* marker : size of marking around marked pixel (will show as colored square)
        x,y : pixels location
        * */
        return mark_dark_pixel(x,y,bmp1 ,(byte)marker,  Color.BLACK);
    }
    public Bitmap mark_dark_pixel_red(int x, int y, Bitmap bmp1, byte marker) {
        /* marker : size of marking around marked pixel (will show as colored square)
        x,y : pixels location
        * */
        return mark_dark_pixel(x,y,bmp1 ,(byte)marker,  Color.RED);
    }
    public Bitmap mark_dark_pixel_blue(int x, int y, Bitmap bmp1, byte marker) {
        /* marker : size of marking around marked pixel (will show as colored square)
        x,y : pixels location
        * */
        return mark_dark_pixel(x,y,bmp1 ,(byte)marker,  Color.BLUE);
    }
    public Bitmap graphicContour(Bitmap bmp , int xmin, int xmax , int ymin , int ymax,int colorOfMarking){
        /*
        marks a squar inside the bitmap
        summon example graphicContour(bmp1,10,900,20,300,COLOR.BLUE)
        * */
        for (int i = xmin; i < xmax; i++) {
            bmp = mark_dark_pixel(i,ymin,bmp, (byte) 1,colorOfMarking);
            bmp = mark_dark_pixel(i,ymax,bmp, (byte) 1,colorOfMarking);
        }
        for (int i = ymin; i < ymax; i++) {
            //((xmin, i, bmp, 1)
            bmp = mark_dark_pixel(xmin,i,bmp, (byte) 1,colorOfMarking);
            bmp = mark_dark_pixel(xmax,i,bmp, (byte) 1,colorOfMarking);
        }
        return  bmp;
    }
    public Bitmap graphicContour(Bitmap bmp , Rectangle r,int colorOfMarking){
        /*
        marks a squar inside the bitmap
        summon example graphicContour(bmp1,10,900,20,300,COLOR.BLUE)
        * */
        for (int i = r.x; i < r.x+r.width; i++) {
            bmp = mark_dark_pixel(i,r.y,bmp, (byte) 1,colorOfMarking);
            bmp = mark_dark_pixel(i,r.y+r.height,bmp, (byte) 1,colorOfMarking);
        }
        for (int i = r.y; i < r.y+r.height; i++) {
            //((xmin, i, bmp, 1)
            bmp = mark_dark_pixel(r.x,i,bmp, (byte) 1,colorOfMarking);
            bmp = mark_dark_pixel(r.x+r.width,i,bmp, (byte) 1,colorOfMarking);
        }
        return  bmp;
    }
    public char getPixelColor(int pixel) {
        //  r= red, g = green, b = blue
        int r = Color.red(pixel);
        int g = Color.green(pixel);
        int b = Color.blue(pixel);
        //black or white
        if(bigTosmall(r+6,g,r-6)&&bigTosmall(r+6,b,r-6)){if(miner(100,r,g,b)==100){return 'w';}else if(maxer(100,r,g,b)==100){return 'k';}}
        if(maxer(65,r,g,b)==65){return 'k';}
        if(bigTosmall(b+10,g,b-10)&&(bigTosmall(b+10,g,r))){return 'a';}//azure
        if(bigTosmall(g,r,b)||bigTosmall(g,b,r)){return 'g';}//green
        if(bigTosmall(b+10,g,b-10)&&(maxer(r,g,b)==r)){return 'r';}//red
        if(bigTosmall(g+10,r,g-10)&&bigTosmall(r+10,g,b)){return  'y';}//yellow
        if(bigTosmall(r,g,b)){if(g<128){return 'c';};return  'o';}//brown or orange
        if(bigTosmall(b,g,r)||bigTosmall(b,r,g)){return  'b';}//blue
        if(bigTosmall(b+6,r,b-6)&&bigTosmall(r+6,b,g+50)){return 'v';}//violet
        if(bigTosmall(r,b,g)){return 'p';}//pink
        return 'w';//white
    }
    public Boolean isBlackPixel(int pixel) {
        //rapid ver for checking if the pixel black
        //  r= red, g = green, b = blue
        int r = Color.red(pixel);
        int g = Color.green(pixel);
        int b = Color.blue(pixel);
        //black or white
        if(bigTosmall(r+6,g,r-6)&&bigTosmall(r+6,b,r-6)){if(maxer(100,r,g,b)==100){return true;}}
        if(maxer(65,r,g,b)==65){return true;}
        return false;//white
    }
    public Boolean bigTosmall(int ... a)
    // return true if input nums decend in value
    {
        for (int i = 0; i < a.length - 1; i++) {
            if (!(a[i] > a[i + 1])) {
                return false;
            }
        }
        return true;
    }
    public String colorChartoString(String ch){
        switch(ch) {
            case "r" :
                return "red";
            case "g" :
                return "green";
            case "b" :
                return "blue";
            case "k" :
                return "black";
            case "w" :
                return "white";
            case "o" :
                return "orange";
            case "p" :
                return "pink";
            case "a" :
                return "azure";
            case "v" :
                return "violet";
            case "y" :
                return "yellow";
            case "c" :
                return "brown";//chiiro
            default :
        }
        return  "";
    }
    public static int miner(int... a) {
        //returns array minimum
        int minimum = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] < minimum) {
                minimum = a[i];
            }
        }
        return minimum;
    }

    public static int maxer(int... a) {
        // returns array maximum
        int maximum = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] > maximum) {
                maximum = a[i];
            }
        }
        return maximum;
    }
    public ImageDepictor directionGetter(Bitmap bmp1)
        /* returns the direction of the latest physical movement
         * TODO add y axis
         * */
    {
        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);
//                }
//                }
            }
        }
        //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;
    }
    public Bitmap markObjects(Bitmap bitmap, int color, ArrayList<Rectangle> rectangles) {
        // marks rectangle list on bitmap
        for (Rectangle rectangle : rectangles) {
            bitmap = graphicContour(bitmap,rectangle.x,rectangle.x + rectangle.width,rectangle.y,rectangle.y + rectangle.height,color);
        }
        return bitmap;
    }
    public Bitmap writeOnDrawable(Bitmap bmp, String text, int colorDotEnum,int textSize,Point point){
        /*
        adds caption to a bitmap image
        example of summon : writeOnDrawable(bmp,"hadouken",Color.Black,200,new Point (0,bmRotated.getHeight()/2));
        * */
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(colorDotEnum);
        paint.setTextSize(textSize);
        Canvas canvas = new Canvas(bmp);
        canvas.drawText(text, point.x, point.y, paint);
        return bmp;
    }
    private Bitmap lineMarker(Bitmap bmp, int y, int thicness,int color) {
        for (int jm = 1; jm < bmp.getWidth() - 10; jm++) {
            for (int i = 0; i <thicness ; i++) {
                bmp.setPixel(jm, y + i, color);
            }
        }
        return bmp;
    }
    public Bitmap markRed(Bitmap bmp){
        for (int i = 0; i < bmp.getHeight()-10; i++) {
            for (int j = 0; j < bmp.getWidth(); j++) {
                int pxl = bmp.getPixel(j,i);
                if(isRedPixel(pxl)){bmp=mark_dark_pixel(j,i,bmp,(byte)1);}
            }
        }
        return  bmp;
    }
    public Boolean isRedPixel(int pixel) {
        //rapid ver for checking if the pixel is redish
        //  r= red, g = green, b = blue
        int r = Color.red(pixel);
        int g = Color.green(pixel)+10;
        int b = Color.blue(pixel);
        //black or white

        return r>100&&r>=g&&g>=20+b;//red
    }
    // original polymarization image detection
    public Boolean activeCube(Bitmap bmp,int x, int y){
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                switch(this.colorTarget) {
                    case 'k' :
                        if(isBlackPixel(bmp.getPixel(10*x+j,10*y+i))){return  true;} break;
                    case 'g' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='g'){return  true;} break;
                    case 'b' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='b'){return  true;} break;
                    case 'w' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='w'){return  true;} break;
                    case 'o' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='o'){return  true;}  break;
                    case 'p' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='p'){return  true;}  break;
                    case 'a' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='a'){return  true;}  break;
                    case 'v' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='v'){return  true;}  break;
                    case 'y' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='y'){return  true;}   break;
                    case 'c' :
                        if(getPixelColor(bmp.getPixel(10*x+j,10*y+i))=='c'){return  true;}     break;
                }//end switch

            }
        }
        return  false;
    }
    public Bitmap cubix(Bitmap bmp){
        //mark cubes containing black color
        Boolean[][] arr = new Boolean[100][100];
        for (int i = 0; i < arr.length-1; i++) {
            Arrays.fill(arr[i], false);
        }
        bmp = scale608h608w(bmp);
        for (int i = 1; i < 90; i++) {
            for (int j = 1; j < 90; j++) {
                if(activeCube(bmp,j,i)){bmp=graphicContour(bmp,10*j,10*j+10,10*i,10*i+10,Color.YELLOW);}
            }
        }
        return bmp;
    }
    public Bitmap scale608h608w(Bitmap bmp){
        //scale image down to dimension x dimension
        return Bitmap.createScaledBitmap(bmp, 1000, 1000, true);
    }
    public ArrayList<Detectee> detectees = new ArrayList<Detectee>();
    public Bitmap polyDetection(Bitmap bmp){
        Boolean[][] arr = new Boolean[100][100];
        for (int i = 0; i < arr.length-1; i++) {
            Arrays.fill(arr[i], false);
        }
        bmp = scale608h608w(bmp);
        for (int i = 1; i < 95; i++) {
            for (int j = 1; j < 95; j++) {
                if(activeCube(bmp,j,i)){arr[i][j]=true; }
            }
        }
        for (int i = 1; i < 95; i++) {
            arr[i][94]=false;
        }
        Boolean connect=false;
        int k1 = 0;int k2 =0;
        LineV2 curLine=null;
        LineV2 lastLine = null;
        Boolean addLine = false;
        ArrayList<LineV2> lines = new ArrayList<LineV2>();
        for (int i = 1; i < 95; i++) {
            for (int j = 1; j < 95; j++) {
                if(!connect&&arr[i][j]){
                    curLine=new LineV2(new Point(j,i));addLine=true;connect=true;continue;}
                if(connect&&arr[i][j]){curLine.puffLine();continue;}
                if(connect&&!arr[i][j]){connect=false;
                //check with prev lines
                    for (int k = k1; k < k2; k++) {
                        if(lines.get(k).touchingNextLine(curLine)){if(!lines.get(k).getAbsorbed()){curLine.absorb(lines.get(k));lastLine=curLine;}
                        else {lastLine.absorbOnLine(curLine);curLine=lastLine;addLine=false;}}
                    }

                    if(addLine){lines.add(curLine);}
                }
            }
            k1=k2;
            k2=lines.size();
        }
        detectees = new ArrayList<Detectee>();
        for (LineV2 l : lines)
        {if(!l.getAbsorbed()){detectees.add(new Detectee(l));}}
        for (Detectee det : detectees){
            bmp=graphicContour(bmp,det.getRectangle().x*10,det.getRectangle().x*10+10*det.getRectangle().width,10*det.getRectangle().y,10*det.getRectangle().y+10*det.getRectangle().height,Color.BLUE);
        }
        return bmp;
    }
}


where

Last edited by Moti Barski on Sat May 06, 2023 9:19 am; edited 1 time in total

descriptionartificial eye - java A.Eye artificial eye fastest image detection algorithm and code EmptyRe: java A.Eye artificial eye fastest image detection algorithm and code

more_horiz

Code:

package com.yotamarker.eyeresearch;

import java.util.ArrayList;

public class AEyeClassifier {
    /*
    * resulting object of a processed image string representations of objects
    * within an image
    */
    private ArrayList<String> lv1 = new ArrayList<String>(); // all captured items
    private String lv2; // outline of biggest item
    private String lv3; // insides of captured item
    private boolean connectable;
}


Code:

package com.yotamarker.eyeresearch;

import android.support.constraint.solver.widgets.Rectangle;

import java.util.HashSet;
import java.util.Iterator;

public class Detectee {
    private Rectangle rectangle;
    private HashSet<Integer> points = new HashSet(); // x,y

    public Detectee(LineV2 l1) {
        super();
        this.points = (HashSet<Integer>) l1.getPoints();
        int maxx = -1;
        int maxy = -1;
        int minx = 90001;
        int miny = 90001;
        Iterator<Integer> i = this.points.iterator();
        while (i.hasNext()) {
            int p1 = i.next();
            int x = p1 / 100;
            int y = p1 % 100;
            maxx = maxer(x, maxx);
            maxy = maxer(y, maxy);
            minx = miner(x, minx);
            miny = miner(y, miny);
        }
        this.rectangle = new RectangleCtor(minx, miny, maxx, maxy);
    }

    public Rectangle getRectangle() {
        return rectangle;
    }

    public static int miner(int... a) {
        // returns array minimum
        int minimum = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] < minimum) {
                minimum = a[i];
            }
        }
        return minimum;
    }

    public static int maxer(int... a) {
        // returns array maximum
        int maximum = a[0];
        for (int i = 1; i < a.length; i++) {
            if (a[i] > maximum) {
                maximum = a[i];
            }
        }
        return maximum;
    }
}


Code:

package com.yotamarker.eyeresearch;

import android.graphics.Bitmap;

public class ImageDepictor {
    // an image and its description, usually the image would contain markings
    private Bitmap bmp = null;
    private String depiction = "";

    public Bitmap getBmp() {
        return bmp;
    }

    public void setBmp(Bitmap bmp) {
        this.bmp = bmp;
    }

    public String getDepiction() {
        return depiction;
    }

    public void setDepiction(String depiction) {
        this.depiction = depiction;
    }
}

descriptionartificial eye - java A.Eye artificial eye fastest image detection algorithm and code EmptyRe: java A.Eye artificial eye fastest image detection algorithm and code

more_horiz

Code:

package com.yotamarker.eyeresearch;

import android.graphics.Point;

import java.util.HashSet;

public class LineV2 {
    private HashSet<Integer> points = new HashSet(); // x,y
    private Point start;
    private int activeRange;

    public Point getStart() {
        return start;
    }

    public int getActiveRange() {
        return activeRange;
    }

    private Boolean absorbed = false;

    public LineV2(Point p1) {
        start = new Point(p1);
        activeRange = 0;
        points.add(p1.x * 100 + p1.y);
    }

    public Boolean touchingNextLine(LineV2 nxtLine) {
        if (!(nxtLine.getStart().y == this.start.y + 1)) {
            return false;
        }
        return !((start.x > nxtLine.getStart().x + nxtLine.getActiveRange())
                || start.x + activeRange < nxtLine.getStart().x);
    }

    public Boolean getAbsorbed() {
        return absorbed;
    }

    public void setAbsorbed(Boolean absorbed) {
        this.absorbed = absorbed;
    }

    public void absorb(LineV2 food) {
        this.points.addAll(food.getPoints());
        food.setAbsorbed(true);
    }

    public void absorbOnLine(LineV2 food) {
        this.activeRange = food.start.x + food.activeRange;
    }

    public void setActiveRange(int activeRange) {
        // delete me
        this.activeRange = activeRange;
    }

    public void puffLine() {
        this.activeRange++;
        this.points.add((start.x + activeRange) * 100 + start.y);
    }

    public HashSet<Integer> getPoints() {
        return points;
    }

}


Code:

package com.yotamarker.eyeresearch;

import android.support.constraint.solver.widgets.Rectangle;

public class RectangleCtor extends Rectangle {
    public RectangleCtor(int x,int y,int x2,int y2) {
        this.x = x;
        this.y = y;
        this.width = x2-x;
        this.height = y2-y;
    }
}


Code:

package com.yotamarker.eyeresearch;

import java.util.Calendar;
import java.util.Date;

public class TimeGate {
    // a gate that only opens x minutes after it has been set
    private int pause = 1;
    private Date openedGate = addMinutesToJavaUtilDate(new Date(), pause);
    private Date checkPoint = new Date();
    public TimeGate(int minutes) {
        super();
        this.pause = minutes;
    }
    public TimeGate() {
    }
    public Boolean isClosed() {
        return !openedGate.before(new Date());
    }
    public void close() {
        this.openedGate = addMinutesToJavaUtilDate(new Date(), pause);
    }
    public void close(int minutes) {
        Date now = new Date();
        openedGate = addMinutesToJavaUtilDate(now, minutes);
    }
    private Date addMinutesToJavaUtilDate(Date date, int minutes) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MINUTE, minutes);
        return calendar.getTime();
    }
    public void setPause(int pause) {
        if(pause <60 && pause >0) {
            this.pause = pause;}
    }

    public void resetCheckPoint() {
        this.checkPoint = new Date();
    }

    public int givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen() {
        Date now = new Date();
        long diff = now.getTime() - this.checkPoint.getTime();
        long diffSeconds = diff / 1000 % 60;
        // long diffMinutes = diff / (60 * 1000) % 60;
        // long diffHours = diff / (60 * 60 * 1000) % 24;
        // long diffDays = diff / (24 * 60 * 60 * 1000);
        // System.out.print(diffDays + " days, ");
        // System.out.print(diffHours + " hours, ");
        // System.out.print(diffMinutes + " minutes, ");
        // System.out.print(diffSeconds + " seconds.");
        return (int) diffSeconds;
    }
    public int milisecInterval() {
        Date now = new Date();
        long diff = now.getTime() - this.checkPoint.getTime();
        long diffMiliSeconds = diff / 1000;
        // long diffMinutes = diff / (60 * 1000) % 60;
        // long diffHours = diff / (60 * 60 * 1000) % 24;
        // long diffDays = diff / (24 * 60 * 60 * 1000);
        // System.out.print(diffDays + " days, ");
        // System.out.print(diffHours + " hours, ");
        // System.out.print(diffMinutes + " minutes, ");
        // System.out.print(diffSeconds + " seconds.");
        return (int) diffMiliSeconds;
    }
}


descriptionartificial eye - java A.Eye artificial eye fastest image detection algorithm and code EmptyRe: java A.Eye artificial eye fastest image detection algorithm and code

more_horiz

Code:

package com.yotamarker.eyeresearch;

import android.content.Context;
import android.media.MediaPlayer;

public class TTSVoice {
    MediaPlayer mediaPlayer;
    Context contextl;
    public TTSVoice(Context context) {
        this.contextl = context;
    }
    public void speak(String text){
        switch(text) {
            case "red" :
                mediaPlayer = MediaPlayer.create(this.contextl, R.raw.red);
                mediaPlayer.start();
                break;
            case "blue" :
                mediaPlayer = MediaPlayer.create(this.contextl, R.raw.blue);
                mediaPlayer.start();
                break;
            case "green" :
                mediaPlayer = MediaPlayer.create(this.contextl, R.raw.green);
                mediaPlayer.start();
                break;
            case "black" :
                mediaPlayer = MediaPlayer.create(this.contextl, R.raw.black);
                mediaPlayer.start();
                break;
            case "orange" :
                mediaPlayer = MediaPlayer.create(this.contextl, R.raw.orange);
                mediaPlayer.start();
                break;
            case "white" :
                mediaPlayer = MediaPlayer.create(this.contextl, R.raw.white);
                mediaPlayer.start();
                break;
            default :

        }
    }
}

descriptionartificial eye - java A.Eye artificial eye fastest image detection algorithm and code EmptyRe: java A.Eye artificial eye fastest image detection algorithm and code

more_horiz

Code:

package com.yotamarker.eyeresearch;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Point;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.StrictMode;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.solver.widgets.Rectangle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {

    //finals
    //take picture request code
    final private int CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE=1; // permission img from camera
    final private int CAMERA_SIMPLE_REQUEST = 2; // img from gallerys

    //pointer to image view
    ImageView imgPicture;
    //pointer to context
    Context context;
    //pointer to fileName
    String fileName;
    TTSVoice ttsVoice = null;
    AEye aEye = new AEye();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //calling the set pointer
        setPointer();
    }

    private void setPointer() {
        //get the context
        Log.i("test", "hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
        this.context=this;
        ttsVoice = new TTSVoice(this);
        //check for camera permission, since camera is privacy violate
        //we need to ask permission by code from android 6 and above
        checkForPermissions();
        //pointer to camera on screen
        imgPicture=findViewById(R.id.imgPicture);
        //set a click listener to our button
        findViewById(R.id.btnCamera).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //check if user turned off the permission
                checkForPermissions();
                //fire the intent for camera if we have a permission to work
                if (checkForPermissions())
                {
                    //dispatch the image taking intent
                    dispatchTakeImageIntent();
                }
            }
        });
        findViewById(R.id.btnCameraSimple).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dispatchCameraSimple();
            }
        });
    }
    private void dispatchCameraSimple() {
        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(intent, CAMERA_SIMPLE_REQUEST);
        }
    }
    private boolean checkForPermissions() {
        Log.e("CHK permission", "checkForPermissions: checking permission" );
        //we create a list of permission to ask, so we can add more later on.
        List<String> listPermissionsNeeded = new ArrayList<>();
        //check if we have a permission for camera
        int camPerm = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
        int writePerm = ContextCompat.checkSelfPermission(this,Manifest.permission.WRITE_EXTERNAL_STORAGE);
        int readPerm = ContextCompat.checkSelfPermission(this,Manifest.permission.READ_EXTERNAL_STORAGE);

        //we don't have the permission
        if (camPerm == PackageManager.PERMISSION_GRANTED && writePerm == PackageManager.PERMISSION_GRANTED && readPerm == PackageManager.PERMISSION_GRANTED) {
            //we have a permission we can move next
            return true;
        }
        listPermissionsNeeded.add(Manifest.permission.CAMERA);
        listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        listPermissionsNeeded.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        if (!listPermissionsNeeded.isEmpty()) {
            ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE);
        }
        return false;
    }

    //we have a feedback from the user for permission
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        //checking if we got a permission result
        Log.e("camera", "onRequestPermissionsResult: request");
        if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Log.e("Permission", "onRequestPermissionsResult: camera true ");
            dispatchTakeImageIntent();
        } else {
            //tell the user why we can not take pictures.
            Toast.makeText(context, "We can not take picture without permission", Toast.LENGTH_SHORT).show();
        }
    }

    //we calling system intent of the camera
    private void dispatchTakeImageIntent() {
        //to avoid api26+ policy restrictions.
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        //we call the android image capture
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");

        //we creating a filename so we can use it later on and put the picture inside the imageView
        fileName = Environment.getExternalStorageDirectory() + File.separator + UUID.randomUUID().toString() + ".jpg";
        File file = new File(fileName);
        //we setting a global pointer to the file location
        Log.e("fileName", "dispatchTakeImageIntent: "+fileName );
        //telling the image capture intent what will be the file name of our image
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        //since it can create exception, we surround it with try/catch block to avoid exception and application crash
        try {
            //call the intent and wait for result after intent is closed.
            startActivityForResult(intent, CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE);
        } catch (Exception e) {
            Log.e("Intent", "dispatchTakeImageIntent: \n" + e.getLocalizedMessage());
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode == CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE) // finished manual cam capture
        {
            try {
                Log.e("camera", "onActivityResult: "+fileName );
                //Get our saved file into a bitmap object:
                final File file = new File(fileName);

                //read the image from the file and convert it to bitmap;
                Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());

                //get exif data (extra information) from the image so we will know orientation of the image
                ExifInterface exif = null;
                try {
                    exif = new ExifInterface(fileName);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                assert exif != null;
                int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                        ExifInterface.ORIENTATION_UNDEFINED);
                //we will rotate the image so we can see it depending on screen rotation.
                Bitmap bmRotated =rotateImage(myBitmap, orientation);
                //ArrayList<Rectangle> allObjects = aEye.detectObjects(bmRotated);
                http://imgPicture.setImageBitmap(aEye.detectObjects2(bmRotated));
                http://imgPicture.setImageBitmap(aEye.detectObjectsV3(bmRotated));
                http://imgPicture.setImageBitmap(aEye.detectObjectsOnMiddle(bmRotated));//last test
                http://Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true)
                TimeGate tiempo = new TimeGate();
                tiempo.resetCheckPoint();
                //Bitmap testScale = Bitmap.createScaledBitmap(bmRotated, 608, 608, true);
                //Bitmap testScale = aEye.scaledObjectDetection608(bmRotated);
                //Bitmap testScale = aEye.markRed(bmRotated);
                //Bitmap testScale = aEye.cubix3(bmRotated);
                //Bitmap testScale = aEye.polyDetection(bmRotated);
                aEye.setColorTarget('o');
                Bitmap testScale = aEye.polyDetection(bmRotated);
                //Bitmap testScale = aEye.scaledObjectDetection608(bmRotated);
                //Bitmap testScale = aEye.markOutlines(bmRotated);
                int msg = tiempo.givenTwoDateTimesInJava8_whenDifferentiatingInSeconds_thenWeGetTen();
                Toast.makeText(this, msg+" seconds, width :" + testScale.getWidth() + " height :" + testScale.getHeight(), Toast.LENGTH_LONG).show();
                http://imgPicture.setImageBitmap(Bitmap.createScaledBitmap(bmRotated, 608, 608, true));
                imgPicture.setImageBitmap(testScale);
//                ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>();
//                rectangles.add(new RectangleCtor(5, 5, 60, 600));
//                rectangles.add(new RectangleCtor(100, 100, 500, 500));
//                rectangles.add(new RectangleCtor(200, 100, 600, 600));
//                rectangles.add(new RectangleCtor(50, 50, 300, 350));
                http://imgPicture.setImageBitmap(aEye.writeOnDrawable(bmRotated,"hadouken",Color.BLUE,200,new Point (0,bmRotated.getHeight()/2)));
                //ImageDepictor imageDepictorTest = aEye.directionGetter(bmRotated);
                http://Toast.makeText(this, imageDepictorTest.getDepiction(), Toast.LENGTH_LONG).show();
                http://imgPicture.setImageBitmap(bmRotated);
                //now we can set the image into the image view that we have

                http://Toast.makeText(this, Color.red(bmRotated.getPixel(10,10)) +"", Toast.LENGTH_LONG).show();
                //test area

                //String testPixel1 = aEye.getPixelColor(bmRotated.getPixel(10,10)) +"";
                http://Toast.makeText(this, aEye.colorChartoString(testPixel1), Toast.LENGTH_LONG).show();
                http://ttsVoice.speak(aEye.colorChartoString(testPixel1));
                //Bitmap bmpTest = aEye.mark_dark_pixel(10,10,bmRotated, (byte) 50);


                http://imgPicture.setImageBitmap(imageDepictorTest.getBmp());
                http://imgPicture.setImageBitmap(bmRotated);
            } catch (Exception e) {
                //printing the error that we have without crashing the application....
                e.printStackTrace();
            }
        }

        if (requestCode == CAMERA_SIMPLE_REQUEST && resultCode == RESULT_OK) { // finished gallery img selection
            Uri photoUri=data.getData();
            try {
                Bitmap selectedImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);
                imgPicture.setImageBitmap(selectedImage);

            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

    private Bitmap rotateImage(Bitmap myBitmap, int orientation) {
        //we create a matrix, so we can put the image on it and just rotate
        //it will be much faster then copy pixel by pixel
        Matrix matrix = new Matrix();
        //depending on the orientation that we got from the exif, we will rotate
        //in this sample we will deal with all kind of rotating from api 15 to api 27
        switch (orientation) {
            case ExifInterface.ORIENTATION_NORMAL:
                //all is o.k no need to rotate, just return the image
                return myBitmap;
            case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                //flip the matrix horizontal
                matrix.setScale(-1, 1);
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                //roate the matrix 180 degrees
                matrix.setRotate(180);
                break;
            case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                //flip the picture vertical
                matrix.setRotate(180);
                matrix.postScale(-1, 1);
                break;
            case ExifInterface.ORIENTATION_TRANSPOSE:
                //rotate 90 degrees and flip
                matrix.setRotate(90);
                matrix.postScale(-1, 1);
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                //rotate 90 degress
                matrix.setRotate(90);
                break;
            case ExifInterface.ORIENTATION_TRANSVERSE:
                //rotate 90 degrees to other side and flip
                matrix.setRotate(-90);
                matrix.postScale(-1, 1);
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                //roate 90 degrees to other side
                matrix.setRotate(-90);
                break;
            default:
                //if we have a case that we don't thought of , just return the picture.
                return myBitmap;
        }
        try {
            //create an image from our rotated solution
            Bitmap bmRotated = Bitmap.createBitmap(myBitmap, 0, 0, myBitmap.getWidth(), myBitmap.getHeight(), matrix, true);
            //recycle the data by calling the garbage collector
            //in this case, we free memory for big images.
            myBitmap.recycle();
            //return the rotated image
            return bmRotated;
        } catch (OutOfMemoryError e) {
            //if we have memory leak , we need to know about it.
            e.printStackTrace();
            return null;
        }
    }
}
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply