Ask Your Question

Vishal Chhatwani's profile - activity

2015-04-21 05:00:52 -0600 commented question Convert Gray image into LBP image

@berak how would I do that? writing C++ code in android. Can u refer a good link? And why cant I do that in Java? This means C++ is more efficient than Java.

2015-04-20 18:53:29 -0600 received badge  Editor (source)
2015-04-19 14:56:03 -0600 commented question Convert Gray image into LBP image

@berak So far I have detected the eyes and face using haarcascade. Converted them to gray image. So now I have a gray image of that detected region(in this case eyes) on which i want to apply LBP. I know the concept of how LBP works but having trouble in writing the code in java. Can you please help me with that ?

2015-04-19 00:50:16 -0600 received badge  Organizer (source)
2015-04-19 00:49:32 -0600 asked a question Convert Gray image into LBP image

Hello everyone,

I want to detect the eye blink in android OpenCV. I have been suggested to use LBP and SVM Classification for better results. I have been looking at different places including this and this but having trouble in understanding the code. I want the code in Java and I am having problems in converting the C++ code into Java as there are some function which are different in both of them. Can someone kindly give me a sample code to convert gray image to LBP image so that I can apply SVM on it. Need it badly. Please help.. Here is a code in C++. I need this in Java.

Mat LBP(Mat img){
Mat dst = Mat::zeros(img.rows-2, img.cols-2, CV_8UC1);
for(int i=1;i<img.rows-1;i++) {
    for(int j=1;j<img.cols-1;j++) {
        uchar center = img.at<uchar>(i,j);
        unsigned char code = 0;
        code |= ((img.at<uchar>(i-1,j-1)) > center) << 7;
            code |= ((img.at<uchar>(i-1,j)) > center) << 6;
        code |= ((img.at<uchar>(i-1,j+1)) > center) << 5;
        code |= ((img.at<uchar>(i,j+1)) > center) << 4;
        code |= ((img.at<uchar>(i+1,j+1)) > center) << 3;
        code |= ((img.at<uchar>(i+1,j)) > center) << 2;
        code |= ((img.at<uchar>(i+1,j-1)) > center) << 1;
        code |= ((img.at<uchar>(i,j-1)) > center) << 0;
        dst.at<uchar>(i-1,j-1) = code;
    }
}
return dst;

}

Thanks in advance.

2015-04-11 15:03:51 -0600 asked a question Detecting only one face using OpenCV in android

Hello everyone. So what I want to do is to detect a face to perform some image processing operations. I got a sample code of face detection from OpenCV library. But that code is for detecting multiple faces. But I just want to detect single face. Here is a code:

MatOfRect faces = new MatOfRect();

        if (mJavaDetector != null)
            mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2,
                    2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                    new Size(mAbsoluteFaceSize, mAbsoluteFaceSize),
                    new Size());

    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++) {
        Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(),
                FACE_RECT_COLOR, 2);
        xCenter = (facesArray[i].x + facesArray[i].width + facesArray[i].x) / 2;
        yCenter = (facesArray[i].y + facesArray[i].y + facesArray[i].height) / 2;
        Point center = new Point(xCenter, yCenter);

You can see, there is a for loop to detect multiple faces. When I try to remove that for loop and change that array type variable, I get an error. Can someone please tell me how to use those tl() and br() methods inside for loop if I want to detect just one face.

Thanks in advance.

2015-04-11 14:45:43 -0600 commented question how to detect only one face.

I know this is a very old post. But I was just searching around the internet for same issue. Would you please tell me how did you solve this? @Punith K

2015-04-11 14:42:39 -0600 received badge  Supporter (source)
2015-01-21 08:49:53 -0600 received badge  Enthusiast
2015-01-19 07:41:23 -0600 commented question Face and Eye detection in android

I thought this is related to my problem because the additional code will be related to this class. I could not find any useful code on eye detection in android. So I am really waiting for someone who can help me with this. :)

2015-01-19 07:14:27 -0600 asked a question Face and Eye detection in android

Hello everyone. What I want to do is to detect the yawning and blinking of eyes. So far I have just been able to create a videoview and displayed a camera preview on that videoview. Now I need to apply some techniques like haar cascade or some other to detect the eyes and face. I have been looking all over internet but couldnt find exact solution. Can someone please tell me an easy solution to this.

This is the code of my CameraPreview class so far.

public class CameraPreview extends Activity implements SurfaceHolder.Callback{

    private VideoView videoView = null;
    private SurfaceHolder holder = null;
    private Camera camera = null;
    private static final String TAG = "Video";
    private int cameraId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nextpage);
        cameraId = getFrontCameraId();
        try {


            camera = Camera.open(cameraId);
            camera.setDisplayOrientation(90);
            camera.lock();
        } catch(RuntimeException re) {
            Log.v(TAG, "Could not initialize the Camera");
            re.printStackTrace();
        }

        videoView = (VideoView) this.findViewById(R.id.videoView);
        holder = videoView.getHolder();
        holder.addCallback(this);
    }

    private int getFrontCameraId(){
        int camId = -1;
        int numberOfCameras = Camera.getNumberOfCameras();
        CameraInfo ci = new CameraInfo();

        for(int i = 0;i < numberOfCameras;i++){
            Camera.getCameraInfo(i,ci);
            if(ci.facing == CameraInfo.CAMERA_FACING_FRONT){
                camId = i;
            }
        }

        return camId;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
         Log.v(TAG, "in surfaceCreated");

            try {
                camera.setPreviewDisplay(holder);
                camera.startPreview();
            } catch(IOException e) {
                Log.v(TAG, "Could not start the preview");
                e.printStackTrace();
            }
    }
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub

    }
    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        camera.release();
    }
}

Thanks in advance :)

2015-01-18 14:37:57 -0600 commented question OpenCV apps show blank screen on device

yea waiting for someone who can help me out. :)

2015-01-17 12:40:11 -0600 commented question OpenCV apps show blank screen on device

I am talking about the samples that come with OpenCV installation package. my CPU is ARMv7. I just copied .apk file into my phone and tried to run it. But all of them showing blank screen.

2015-01-16 06:08:22 -0600 asked a question OpenCV apps show blank screen on device

I installed OpenCV 2.4.10(latest version) on my windows and tried to run sample apps on my android phone but they all show a blank screen. I have been looking all over internet for the solution but have not got any. Please help.

Thanks in advance.