Ask Your Question

valexor89's profile - activity

2015-11-26 08:15:01 -0500 commented question get few pixels value of grayscale image with android API

Sorry men, i've found the solution at this question, the problem is that when you use the method get on Mat need to switch the value x and y of cordinates, otherwise could go out of range and return null value.

So must to use as follow: Mat m = something double[] buff = m.get(Y,X); //in this form if want read only few values double value=buff[0]; //contain the pixel intensity for grayscale image //or intensity of one channel according to the model RGB or BGR

However thanks alot all of you.

2015-11-26 06:09:26 -0500 asked a question get few pixels value of grayscale image with android API

Hi men, first of all sorry for my bad englisjh. I need to use a few pixels value of a grayscale image, i've searched everywhere on the web and have understood how read the pixel value but cannot resolve my problem.

In short i have a grayscale image 8UC1, under the significant code:

public boolean verify(Mat pupil, Point center, int r, int i)
{//verifica se i cerchi da disegnare coincidono esattamente con gli occhi
 //ovvero se non si discotano di tanto o anche di poco dall'iride viene escluso
    boolean flag=false;

    int x,y; 
    x = (int) (center.x); 
    y = (int) (center.y);
    int radiusx[] = {0,0};
    int radiusy[] = {0,0};
    radiusx[0] =  (x+r);
    radiusy[0] =  (y+r);
    radiusx[1] =  (x-r);
    radiusy[1] =  (y-r);
    int ep=2;

    double[] data1u,data2u,data3u,data4u; //pixel superiori
    double[] data1d,data2d,data3d,data4d; //pixel inferiori
    double diff1,diff2,diff3,diff4; //differenze tra i pixel
    //primo pixel superiore ed inferiore (orientamento 90° all'asse y1 del cerchio)
    //per alcune ragioni data1u ecc...sono nulli
    //ora usando (int)data1u[0] ottengo il valore dell'intensità
    diff1=(data1u[0]-data1d[0]); //differenza tra intensittà???[1°] e [2°] cordinate pixel
    //secondo pixel superiore ed inferiore (orientamento 180° all'asse y1 cerchio)
    //terzo pixel superiore ed inferiore (orientamento -90° all'asse y1 del cerchio)
    //essendo verso opposto, cambia il verso dell'asse positivo relativo al cerchio
    //quarto pixel superiore ed inferiore (orientamento 0° all'asse y1 del cerchio)
    //controllo: se le differenze sono valori bassi (idealmente zero) è un occhio rilevato male
    double soglia=10;
    if (diff1>soglia && diff2>soglia && diff3>soglia && diff4>soglia) //soglia un certo valore>0 non basso
    return flag;

Sorry for the cofuded code, the important is that pupil is an image not empty in grayscale and 8UC1, i'm sure, and the vectors data1u, etc... are null (viewed with debug) on diff1=(data1u[0]-data1d[0]);

Why is that? Hope in some advices. Thanks you all.

2015-08-19 03:41:25 -0500 received badge  Enthusiast
2015-08-17 13:25:57 -0500 commented question problem with face detection on android

Thank you man, i read and studied more carefully the documentation and now work

2015-08-16 03:13:26 -0500 asked a question problem with face detection on android

HI all. I'm a beginner in android so i have a little difficulty to use openCV here. For my studies i'm doing a face detection for opportunely image processing of that ROI. So i've the code in c++ that work, seeing the official documentation and my c++ code i tried to porting on android, my application work without crash but i can't to draw any rectangle for the faces. I was hoping you could give me any advice for detect and solve my mistake

Here the code that do face detection:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) 
    Mat image = new Mat();
    Mat tmp = new Mat();

    //Convert to RGB
    Imgproc.cvtColor(image, image, Imgproc.COLOR_RGBA2RGB);
    tmp = image.clone();


    //convert to grayscale (the approach works on grayscale images only)
    if (image.channels() == 3)
        Imgproc.cvtColor(image, tmp, Imgproc.COLOR_RGB2GRAY);

    CascadeClassifier face_cascade = new CascadeClassifier();
    String filename="../../resources/lbpcascade_frontalface.xml";

    MatOfRect faces = new MatOfRect();
    //if (face_cascade != null)
        face_cascade.detectMultiScale(tmp, faces, 1.1, 2, 2, new Size(0,0),new Size());

    Rect[] face_cropped = faces.toArray();
    Mat faceROI;
    //for each face found...
    for (int i=0; i< face_cropped.length; i++)
        Core.rectangle(image, face_cropped[i].tl(),face_cropped[i].br(),new Scalar(0,255,0,255),3);


    if (CameraMod >= 2) //for detect if devices has 2 cameras
    //in the case of 2 cameras it takes the front camera
        Core.flip(image, image, 1);

    //return image;
    return image;