Ask Your Question

silvercats's profile - activity

2017-08-29 16:52:16 -0500 received badge  Popular Question (source)
2014-09-09 21:26:03 -0500 asked a question Convexhull drawing doesn't show up

Actually this is JavaCV. I tried to draw the hull around the object but nothing shows up on the image.

import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_highgui.CvCapture;
import com.googlecode.javacv.cpp.opencv_imgproc.CvMoments;

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

public class MomentsMain {

public static void main(String[] args) {

    IplImage img1,imghsv,imgbin;
    CvScalar Bminc = cvScalar(1,44,4,0), Bmaxc = cvScalar(179,255,147,0);

    CvSeq contour1 = new CvSeq(), contour2;
            CvSeq bigContour=new CvSeq();

    CvMemStorage storage = CvMemStorage.create();
            CvMemStorage hullStorage = CvMemStorage.create();
            CvMemStorage storageCont = CvMemStorage.create();
            CvMemStorage defectsStorage = CvMemStorage.create();

    CvMoments moments = new CvMoments(Loader.sizeof(CvMoments.class));

    double areaMax, areaC=0;
    double m10,m01,m_area;

    int posX=0,posY=0;


    CvCapture capture1 = cvCreateCameraCapture(CV_CAP_ANY);
    imghsv = cvCreateImage(cvSize(640,480),8,3);
    imgbin = cvCreateImage(cvSize(640,480),8,1);
    CvSeq hullSeq=new CvSeq();
            CvSeq defects=new CvSeq();
            CvSeq approxContour=new CvSeq();

    int i=1;

    while(i==1)
    {

        img1 = cvQueryFrame(capture1);

        if(img1 ==null) 
            {
                System.err.println("No Image");
                break;
            }

        cvCvtColor(img1,imghsv,CV_BGR2HSV);
        cvInRangeS(imghsv,Bminc,Bmaxc,imgbin);

        contour1 = new CvSeq();
        areaMax= 1000;

        cvFindContours(imgbin,storage,contour1,Loader.sizeof(CvContour.class),
                        CV_RETR_LIST,CV_LINK_RUNS,cvPoint(0,0));

                    cvCircle(img1, cvPoint(posX,posY), 5, cvScalar(0,255,0,0), 9,0,0);

        contour2= contour1;

        while(contour1 != null && !contour1.isNull())
        {
            areaC = cvContourArea(contour1,CV_WHOLE_SEQ,1);

            if(areaC>areaMax)
                            {
                areaMax = areaC;

                            }

            contour1 = contour1.h_next();

        }

        while(contour2 !=null && !contour2.isNull())
        {
                        areaC= cvContourArea(contour2,CV_WHOLE_SEQ,1);

                        if(areaC<areaMax)
                        {
                          cvDrawContours(imgbin,contour2,CV_RGB(0,0,0),CV_RGB(0,0,0),0,CV_FILLED,8,cvPoint(0,0));

                          bigContour=contour2;
                        }

            contour2=contour2.h_next();                                

        }

                    hullSeq = cvConvexHull2(bigContour, hullStorage, CV_COUNTER_CLOCKWISE, 0);

                    defects = cvConvexityDefects(bigContour, hullSeq, defectsStorage);  

                    cvDrawContours(img1,defects , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);

                    cvDrawContours(img1,hullSeq , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);


        cvMoments(imgbin,moments,1);

        m10 = cvGetSpatialMoment(moments,1,0);
        m01 = cvGetSpatialMoment(moments,0,1);
        m_area = cvGetCentralMoment(moments,0,0);

        posX = (int) (m10/m_area);
        posY = (int) (m01/m_area);

        if(posX>0 && posY>0)
            System.out.println("x = "+posX+", y= "+posY);






        cvShowImage("Color",img1);
        cvShowImage("CF",imgbin);
        char c = (char)cvWaitKey(15);
        if(c=='q') break;


    }


    cvReleaseImage(imghsv);
    cvReleaseImage(imgbin);
    cvReleaseMemStorage(storage);
    cvReleaseCapture(capture1);


}

}

I tried to draw a convex hull and convexitydefects around an object using these line in the above mentioned code.

       hullSeq = cvConvexHull2(bigContour, hullStorage, CV_COUNTER_CLOCKWISE, 0);

                    defects = cvConvexityDefects(bigContour, hullSeq, defectsStorage);  

                    cvDrawContours(img1,defects , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);

                    cvDrawContours(img1,hullSeq , CvScalar.BLUE, CvScalar.BLUE, 1,0,0);

It doesn't show anything.drawing a circle to the COG works but the convext hull is not drawn.

2014-09-06 00:36:35 -0500 asked a question How to draw a convexthull and a polygon around the hand in this tutorial

I found this tutorial in JavaCV how to detect a hand gesture. But it doesn't show how to draw the convexhull or a polygon around the palm. Can someone tell me how to do that in this example?

http://www.javacodegeeks.com/2012/12/hand-and-finger-detection-using-javacv.html

2014-09-06 00:32:47 -0500 answered a question Java OpenCV Face detection code not working. Nullpointer exception

it run out that the method "getPath" gives an additional "\" at the beginning. Adding ".substring(1)" tot he "getPath" method fixed this by removing the first unwanted "\". check the line below. Make sure to put .substring to every getPath() method.

 String url1 = getClass().getResource("lena.png").getPath().substring(1);
2014-08-22 11:43:22 -0500 asked a question Java OpenCV Face detection code not working. Nullpointer exception

package javapplication15;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
class DetectFaceDemo {
  public void run() {
    System.out.println("\nRunning DetectFaceDemo");

    // Create a face detector from the cascade file in the resources
    // directory.
    CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
    Mat image = Highgui.imread(getClass().getResource("/lena.png").getPath());

    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.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()) {
        Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
    }

    // Save the visualized detection.
    String filename = "faceDetection.png";
    System.out.println(String.format("Writing %s", filename));
    Highgui.imwrite(filename, image);
  }
}

public class HelloOpenCV {
  public static void main(String[] args) {
    System.out.println("Hello, OpenCV");

    // Load the native library.
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    new DetectFaceDemo().run();
  }
}

http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html

I tried this tutorial mentioned above and got the following error.

Exception in thread "main" java.lang.NullPointerException
at javapplication15.DetectFaceDemo.run(HelloOpenCV.java:28)
at javapplication15.HelloOpenCV.main(HelloOpenCV.java:56)
Java Result: 1

I am pretty sure that the files are present in corresponding folders as mentioned in the Tutorial. I think this is a path issue and I tried things like giving the absolute path and other things that can be found online. Still not luck.

I am suing NetBeans 8.0, OpenCV 2.4.9 and Windows 8

2014-08-03 20:52:18 -0500 asked a question Are all webcams compatible with OpenCV

is a a4tech web cam ok?

2014-08-02 23:44:20 -0500 received badge  Editor (source)
2014-08-02 23:43:37 -0500 asked a question Are all webcams compatible with OpenCV

a4tech cam

Is above a4tech camera compatible? should I buy a logitech one ?

Are all the cameras compatible?

Thank you.