Ask Your Question

Dhara Shah's profile - activity

2019-02-08 07:36:08 -0600 received badge  Famous Question (source)
2018-12-28 11:33:02 -0600 received badge  Notable Question (source)
2017-04-08 15:04:33 -0600 received badge  Popular Question (source)
2017-02-13 07:14:41 -0600 received badge  Notable Question (source)
2016-04-06 13:30:27 -0600 received badge  Popular Question (source)
2014-09-03 23:38:07 -0600 commented question getBackgroundImage not in Java version?

@berak thank u for the suggestion, i will have a look at grabcut, and get back

2014-09-03 02:46:56 -0600 commented question getBackgroundImage not in Java version?

i was thinking of using the backgroundimage method in order to remove the background from the captured frame(just one frame), so that i could detect objects, i saw the alpha version in the list but then theres no sdk for android

2014-09-03 01:56:09 -0600 commented question getBackgroundImage not in Java version?

@berak - is this present now in the 3.0 version?i am using 2.4.9 but getBackgroundimage is still not there. and i cant build using ndk on my system. please help

2014-08-25 03:49:16 -0600 commented answer count the number of objects from the edges

Hi, thank u for your answer, i dont want to involve area at the moment, is there any other way i could do this? becuase i am trying to capture capsules and small pills, whose proper area i know not. :( . Also there are times when a shadow gets included in the area :(. is there a way i could eliminate shadows ??

2014-08-23 09:03:09 -0600 received badge  Student (source)
2014-08-23 06:04:37 -0600 asked a question count the number of objects from the edges

Hi,

I am trying to detect the count of objects in an image captured on which several operations are performed. I capture an image, get the Hue channel and apply the following:

Imgproc.cvtColor(srcMat, dst, Imgproc.COLOR_RGB2HSV);
ArrayList<Mat> channels = new ArrayList<Mat>();
Core.split(srcMat, channels);
Mat satImg = channels.get(0);

Imgproc.medianBlur(satImg , satImg , 11);
Highgui.imwrite(imgPath + "blurred.jpg", satImg);

Imgproc.threshold(satImg, satImg, -1, 255, Imgproc.THRESH_BINARY + Imgproc.THRESH_OTSU);
Highgui.imwrite(imgPath + "satImg_thresh.jpg", satImg);

Once thresholding is applied to the image, i apply a gaussian blur and apply a threshold filter again, and then a bitwise_not operation on the image . Dilation is applied and then edges are obtained using:

Mat edge = new Mat();
Imgproc.Canny(satImg, edge, 35,90); // 40,120 -> to tr  
Log.e("tag","edge: "  + edge.cols());       
edge.convertTo(threshMat,CvType.CV_8U);     
Log.e("tag","dst cols " + threshMat.cols()); 
Highgui.imwrite(imgPath + "canny.jpg", threshMat);

This is the image i get: image description

I then perform dilation out of which i get the image below: image description

There are a couple of questions i have:

  1. I would like to actually fill those edges completely such that it would become a complete ellipse. Yes, i am using fitEllipse for the same but i would like to do it with an edge function if possible. I am using findContours to get the number of outer edges with the flat Imgproc.RETR_EXTERNAL but then as in the image there is that one line extra that gets counted, i wish to neglect that too. Could any one please guide me ?

  2. Sometimes shadows also form a polygon, i would like to ignore shadows also

  3. Is there a way i could only take into picture those contours that are ellipses or circles? Not lines that turn out to be ellipses, and not even those minor dots if there are any.

Please assist

P.S: I am using opencv for android, any help with c++ code is welcome, though i wish an android equivalent would be present.

EDIT:

I have also used this code to draw the contours but it seems that only one edge would be filled completely. rest are ignored

for (int idx = 0; idx < contours.size(); idx++) {
        MatOfPoint  matOfPoint = new MatOfPoint(contours.get(idx));

        double[] values = hierarchy.get(idx, 0);
        double[] secondLevelValues = hierarchy.get(idx, 1);
        if(values != null) {
            Log.e("tag","dst : 0 " + values[0]);
            if(values[0] != -1) {
                if(matOfPoint.total() >= 5) {
                    Log.e("tag","is convex inside first loop : " + Imgproc.isContourConvex(matOfPoint));
                    counter ++;
                }

                /*Moments moments = Imgproc.moments(matOfPoint);
                moments.get_m01();*/
                Imgproc.drawContours(threshMat, contours, idx, new Scalar(255), -1,8,hierarchy,0,new Point());
            }
        }else {
            if(secondLevelValues != null) {
                Log.e("tag","dst : 1 " + secondLevelValues[0]);
                if(secondLevelValues[0] != -1) {
                    if(matOfPoint.total() >= 5) {
                        counter ++;
                        Log.e("tag","is convex inside first loop : " + Imgproc.isContourConvex(matOfPoint));
                    }
                    Imgproc.drawContours(threshMat, contours, idx, new Scalar(255), -1,8,hierarchy,0,new Point());
                }
            }
        }
    }
2014-07-11 07:13:22 -0600 commented question Function 'Point' could not be resolved, Mat not recognized

hi, i changed the path to an outside location of the native jni files, but then i still get the same error. infact, on removing core.hpp line, i get the error in the next lines too.

2014-07-04 05:14:34 -0600 commented question Function 'Point' could not be resolved, Mat not recognized

iv fixed all the bugs in the core file by adding the native cpp dependencies,bt still no luck. :(.. i even get errors like Point function is not defined. in the same file.(2nd screenshot)

2014-07-04 03:26:49 -0600 commented question Function 'Point' could not be resolved, Mat not recognized

No i dont get the error on the next line. :(

2014-07-03 23:09:13 -0600 commented question Function 'Point' could not be resolved, Mat not recognized

yes i have :(. Please find the screenshots attached also..

2014-07-03 07:55:50 -0600 asked a question Function 'Point' could not be resolved, Mat not recognized

I am getting the errors as mentioned in the question.

*Setup Env: *

  1. I have imported OpenCV - SDK -2.4.9 in eclipse (ADT)
  2. I have included the path to the ndk-cmd.exe
  3. Included all the paths to the c++ libraries as needed
  4. Included the path to the jni folder of the sdk in my project

But then in the current project in android, i have the native code written, and i also have

#include <opencv2/core/core.hpp>

but then, even though the errors in core.hpp have been resolved, and when pressing ctrl+click on the file, it leads me to the location, but it shows an error saying:

fatal error: opencv2/core/core.hpp: No such file or directory

Thanks.

EDIT:

Image 1: the dependencies image description

Image 2: the error image description

2014-07-03 06:43:02 -0600 received badge  Supporter (source)
2014-07-03 06:42:54 -0600 commented answer Unresolved inclusion in OpenCV+Android tutorial

This works for std:string issues :).. but i still get a float.h error .. anyway i could resolve that? (+1 tho)

2014-06-30 06:37:54 -0600 commented question Haar Cascade in android

yes true, i removed that piece of line. But i do not know how the detectMultiScale works.. since at times i get the correct count but at times i dont.

2014-06-30 04:08:57 -0600 received badge  Editor (source)
2014-06-30 04:08:39 -0600 asked a question Haar Cascade in android

Hello,

i am new to opencv for android and all that it has to offer. I would like to experiment with detecting pens using opencv and android (no native code in cpp), i have found a haarcascade file for pen detection, but i do not know how to detect the pens using the cascade classifier in pure android code.

This is what i have so far :

try {
            // load cascade file from application resources
            InputStream is = getResources().openRawResource(R.raw.haarcascade);
            File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
            mCascadeFile = new File(cascadeDir, "haarcascade.xml");
            FileOutputStream os = new FileOutputStream(mCascadeFile);

            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = is.read(buffer)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            is.close();
            os.close();

            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());

            mNativeDetector = new DectionBasedTracker(mCascadeFile.getAbsolutePath(), 0);
            cascadeDir.delete();

        } catch (IOException e) {
            e.printStackTrace();
            Log.e("tag", "Failed to load cascade. Exception thrown: " + e);
        }

        mOpenCvCameraView.enableView();

This code is in the onCreate since i am using static linking of opencv library.

While i am calling a method detectPens that takes up the grey mat, the haarcascade file path and also the MatOfRect variable. I do not want to call native methods but rather if possible want to use the methods available in Imgproc file.

Please assist. Thanks.

EDIT: I used the following to get the pens.toArray() length, but i am not sure if it is correct :(

mJavaDetector.detectMultiScale(mGreyMat, pens);