Ask Your Question

super_man1993's profile - activity

2019-04-07 02:04:58 -0500 received badge  Famous Question (source)
2017-08-14 09:35:01 -0500 received badge  Notable Question (source)
2017-06-16 12:42:17 -0500 received badge  Famous Question (source)
2017-05-15 06:47:53 -0500 received badge  Popular Question (source)
2016-11-19 07:52:41 -0500 received badge  Notable Question (source)
2016-07-21 07:26:13 -0500 received badge  Popular Question (source)
2016-02-11 07:48:17 -0500 asked a question Calculating the distance between two points

How do i calculate the distance between two points in java/ opencv

Point point1 = new Point(10,10);
Point point2= new Point(56, 35);

line(image, point1, point2, new Scalar(100, 100, 100));
2016-02-02 10:48:38 -0500 commented answer locateROI not drawing in ROI

okay, thankyou for your reply.. but i am still unsure as i need a co-ordinate of that point corresponding to original image rather than the ROI... using your example...

    Size s = new Size();
    Point p = new Point();
    roiTmp.locateROI(s, p);
   circle(roiTmp, p, 1, new Scalar(255, 0, 255));
System.out.println("Point: ", +  p);

drawing the circle would only output the point in the corner of the image, as it has the coordinates of the point within the ROI rather than the original image ?

2016-02-02 08:21:31 -0500 commented question locateROI not drawing in ROI

the ROI i am trying to find within the larger 'image'. the bounding rect is inside the roiTmp

2016-02-02 07:37:45 -0500 asked a question locateROI not drawing in ROI

I have a rectangle which surrounds some points.. i now want to find the center of the rectangle ( and also the four corners but i havent included that here). I am trying the locateROI function but it works but seems to only add the circle at the top of the image rather than in the ROI....can anyone see where im going wrong??

 newrectangle = Imgproc.boundingRect(points);
                rectangle(roiTmp, newrectangle .tl(), newrectangle .br(), new Scalar(255, 0, 0), 1, 8, 0);

                center = new Point(newrectangle .x * 0.5, newrectangle .y * 0.5 );

                roiTmp.locateROI(image.size(), new Point(newrectangle .x, newrectangle .y));

                circle(image, center, 1, new Scalar(255, 0, 0));
2015-11-28 16:22:59 -0500 commented question searching for colours in java

something like this? (see update) i got errors saying "error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)" so included this in the new mat but hasnt seem to made a difference

2015-11-28 09:26:01 -0500 commented question searching for colours in java

so it cant be done?

2015-11-28 09:05:42 -0500 asked a question searching for colours in java

I have managed to detect the users mouth and draw a rectangle around it, creating the submat 'mouth'. now i would like to draw contours around the mouth. I have decided to do this via colour searching, so I have tried to search for a shade of pink/red within the Mat and then draw lines around it. However, it doesnt seem to work..

Can anyone see where i am going wrong?

       hsvMat = new Mat(mouth.height(), mouth.width(), CvType.CV_32F);
    Imgproc.cvtColor(mouth, hsvMat, Imgproc.COLOR_BGR2HSV, 3);

    Core.inRange(mouth, new Scalar(200,10,255), new Scalar(255,10,100), hsvMat);

    Imgproc.findContours(hsvMat, contours, mContours, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    for (int x = 0; x < contours.size(); x++) {
        Imgproc.drawContours(hsvMat, contours, x, new Scalar(255, 0, 100), 4);

    }
2015-11-17 12:28:26 -0500 commented question Converting Mat to IPLimage in Java / opencv

ive added some code

2015-11-17 12:28:03 -0500 received badge  Editor (source)
2015-11-17 11:33:59 -0500 commented question Converting Mat to IPLimage in Java / opencv

okay thankyou. dont suppose you know how i can convert a mat to an iplimage??

2015-11-17 11:09:59 -0500 asked a question Converting Mat to IPLimage in Java / opencv

Is there any way to covert a Mat to an IPLimage in java or opencv??? Trying to implement Flandmark in Java, but i need to change the saved image to iplimage to do this. Thanks,

  for (Rect rect : faceDetections.toArray()) {

            int[] bbox = new int[4];
            bbox[0] = rect.x;
            bbox[1] = rect.y;
            bbox[2] = rect.x + rect.width;
            bbox[3] = rect.y + rect.height;
   //Mat 'image' is a image of the users face, done in another class
            //convert to Iplimage here from Mat
//flandmark only works with iplimage so need to convert to mat
            final IplImage input = null;

                flandmark.flandmark_detect(input, bbox, model, landmarks);
            // convert back to Mat here

                // display face landmarks
                rectangle(image, new Point(bbox[0], bbox[1]), new Point(bbox[2], bbox[3]), new Scalar(255, 0, 0));
                rectangle(image, new Point((int) model.bb().get(0), (int) model.bb().get(1)), new Point((int) model.bb().get(2), (int) model.bb().get(3)), new Scalar(0, 0, 255));
                circle(image, new Point((int) landmarks[0], (int) landmarks[1]), 3, new Scalar(0, 0, 255), CV_FILLED, 8, 0);

            for (int i = 2; i < 2 * model.data().options().M(); i += 2) {
                circle(image, new Point((int) (landmarks[i]), (int) (landmarks[i + 1])), 3, new Scalar(255, 0, 0), CV_FILLED, 8, 0);
            }
        }
2015-11-16 14:30:48 -0500 asked a question Flandmark in Java

I am trying to implement flandmark in Java & opencv, I have got it all working except I am using Mat instead of IplImage which means when i try to detect in the image, it doesnt work. in the code below, 'input' is a Mat. Since 'input' needs to be IplImage, does anyone know how i can convert this to an IplImage from a Mat??

flandmark.flandmark_detect(input,bbox, model, landmarks);

I also cant seem to find the import for IplImage in opencv, which confuses me alot..

2015-11-14 05:50:05 -0500 commented answer Facial feature detection

did you get this working?? can you share any code?

2015-11-09 08:55:21 -0500 commented question Java Opencv import for SVM

looked into it, but unsure how to implement it into my application.. got any good links / tutorials where to start with doing this?

2015-11-08 10:58:30 -0500 commented question Java Opencv import for SVM

ahh yeah its open cv 3

2015-11-08 07:45:31 -0500 asked a question Java Opencv import for SVM

I am working on an gender recognition app using java and i have detected the users face using open cv and now i am looking into using SVM as part of it. Is it possible to do it in Java as most of the code i have seen has been in C++. I have found many tutorials online about this but i am still unsure how to start it using java.. I wanted to train the different genders on my laptop, then import the xml to the android. Anyone got any pointers or starter code for me to do this?

Any help would be massively appreciated

Thanks,

2015-10-10 10:00:35 -0500 commented answer Eye detection - OpenCV

any advice on how to do it? ive tried to change it from rectangle to circle but had no luck :(

2015-10-08 13:53:34 -0500 received badge  Enthusiast
2015-10-07 14:08:49 -0500 asked a question Eye detection - OpenCV

I am creating an android application that locates the users eyes. I have managed to get it working perfectly using a rectangle around the eyes. However, i would much prefer it if instead of rectangles, it was a circle around the eye. Does anybody know how i can do this? Also another issue i am having is that sometimes it draws alot of rectangles around the page where it thinks there is an eye. any way of stopping this ? Thanks in advance. Below is my code for drawing the rectangle around the eyes.

for (Rect rect : eyeDetections.toArray()) {

            rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0,255,0));
            image.submat(rect.y, rect.y + rect.height, rect.x, rect.x + rect.width); // just the face. return this mat

        }
2015-08-12 11:48:12 -0500 asked a question Loss of quality on saved image - open cv

I am doing some image modifying using open cv and when i save the image, i lose quality and it becomes very blurred and pixelated...
I have tried using compression methods but doesnt seem to be working.. is there a solution for this? Any help would be greatly appreciated..

jpegCallback = new Camera.PictureCallback() {

                public void onPictureTaken(byte[] data, Camera camera) {
                    Mat jpegData = new Mat(1, data.length, CvType.CV_8UC1);
                    jpegData.put(0, 0, data);

                    Mat bgrMat = Imgcodecs.imdecode(jpegData, Imgcodecs.IMREAD_COLOR);
                    Core.transpose(bgrMat, bgrMat);
                    Core.flip(bgrMat, bgrMat, 0);
                    Imgproc.resize(bgrMat, bgrMat, bgrMat.size());

                    File storagePath = new File(Environment.
                            getExternalStorageDirectory() + "/Emotion Detection/");
                    storagePath.mkdirs();
                    File myImage = new File(storagePath,
                            Long.toString(System.currentTimeMillis()) + ".png");
                    String imageString = myImage.toString();

                    MatOfInt mPngCompressionRate = new MatOfInt(Imgcodecs.CV_IMWRITE_PNG_COMPRESSION, 9);

                    Imgcodecs.imwrite(imageString, bgrMat, mPngCompressionRate);
2015-08-11 06:37:55 -0500 asked a question getResources() on null object reference

I keep getting this error - "Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference"

I have made a camera that saves an image. I am now trying to detect faces in that image, but i keep getting this error when i run the code.. any help? I believe its because i am not passing the context to the facedetection class but i have tried many attempts with no success.. thanks

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Camera();

        jpegCallback = new Camera.PictureCallback() {

            public void onPictureTaken(byte[] data, Camera camera) {
                Mat jpegData = new Mat(1, data.length, CvType.CV_8UC1);
                jpegData.put(0, 0, data);

                Mat bgrMat = Imgcodecs.imdecode(jpegData, Imgcodecs.IMREAD_COLOR);
                Core.transpose(bgrMat, bgrMat);
                Core.flip(bgrMat, bgrMat, 0);
                Imgproc.resize(bgrMat, bgrMat, bgrMat.size());

                File storagePath = new File(Environment.
                        getExternalStorageDirectory() + "/Emotion Detection/");
                storagePath.mkdirs();
                File myImage = new File(storagePath,
                        Long.toString(System.currentTimeMillis()) + ".jpg");
                String imageString = myImage.toString();
                Mat newMat = new FaceDetection().run(bgrMat);
                Imgcodecs.imwrite(imageString, newMat);

                camera.startPreview();
                Toast.makeText(MainActivity.this,
                        "Picture Saved", Toast.LENGTH_LONG).show();
            }
        };
    }

Then in my facedetection class:

class FaceDetection extends Activity {

    private static final String    TAG                 = "OCVSample::Activity";
    private CascadeClassifier      mJavaDetector;
    private File                   mCascadeFile;

    public Mat run(Mat image) {
        System.out.println("\nRunning Face Detection");
        // Create a face detector from the cascade file in the resources
        // directory.
        // load cascade file from application resources
        InputStream is = getResources().openRawResource(R.raw.lbpcascade_frontalface);
        File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
        mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
        try {
            FileOutputStream os = new FileOutputStream(mCascadeFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
        if (mJavaDetector.empty())
        {
            Log.e(TAG, "Failed to load cascade classifier");
            mJavaDetector = null;
        }
        else
            Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());

        cascadeDir.delete();


        // Detect faces in the image.
        // MatOfRect is a special container class for Rect.
        MatOfRect faceDetections = new MatOfRect();
        mJavaDetector.detectMultiScale(image, faceDetections);

        System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
        // Draw a bounding box around each face.
        for (Rect rect : faceDetections.toArray()) {
            rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
        }

        return image;
    }
}
2015-08-09 10:47:33 -0500 asked a question Saving an image using OpenCV & Android

Hi, using java, i have created a camera using surface view.. I am trying to save the image using OpenCV so that i can modify the image (crop, resize etc) but i have having trouble converting the image to a MAT and then saving it.. Any help would be greatly appreciated if you can see where i am going wrong..

        jpegCallback = new Camera.PictureCallback() {

        public void onPictureTaken(byte[] data, Camera camera) {
            Mat jpegData = new Mat(1, data.length, CvType.CV_8UC1);
            jpegData.put(0, 0, data);
            Mat bgrMat = Imgcodecs.imdecode(jpegData, Imgcodecs.IMREAD_COLOR);
            Imgproc.resize(bgrMat, bgrMat, new Size(620, 344));
            MatOfByte matOfByte = new MatOfByte();

            Imgcodecs.imencode(".png", bgrMat, matOfByte);
            byte[] byteArray = matOfByte.toArray();

            try
            {
             Imgcodecs.imread(byteArray);                    
                out.write(data);
                out.flush();
                out.close();