Ask Your Question

rat's profile - activity

2020-10-02 14:48:14 -0600 received badge  Famous Question (source)
2016-04-27 01:57:35 -0600 received badge  Notable Question (source)
2015-09-25 08:13:08 -0600 received badge  Popular Question (source)
2013-09-17 05:34:01 -0600 asked a question find all regions in bitmap image (Whole White color) where lines cross each other and create regions.

Create a white color bitmap. Draw a lot black lines on the bitmap. Use find contour to find all regions in the bitmap. Color it using different color. How can we do this ?

//srcMatrix create
Mat srcMat = new Mat();
srcMat.create(100, 100, CvType.8UC3);

// create a tmp matrix
Mat tmpMat = new Mat();

// Make it to sizeof srcMatrix and 
// make channel to 1
tmpMat.create( srcMat.cols(), srcMat.rows, CvType.8UC1) 

// clear it
tmpMat.setTo(new Scalar(0));

// draw somany lines on the tmpMat
core.Line(tmpMat .... );
core.Line(tmpMat .....
core.Line(tmpMat .....
core.Line(tmpMat .....

// make it binary image
Imgproc.cvtColor(tmpMat , tmpMat , Imgproc.COLOR_RGB2GRAY);

// make it blur
Imgproc.blur( tmpMat, tmpMat , new Size(3,3));

//find canny
Mat mCanny = tmpMat.clone();
Imgproc.Canny(mCanny ,mCanny, 2,4); 

// find Contour
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(mCanny, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

// draw contour

Here i want to detect all regions seperated by lines. When i use drawcontour, it detects not all regions...only some.

2013-09-17 05:25:37 -0600 received badge  Scholar (source)
2013-09-16 09:59:50 -0600 commented answer Get all points inside a rectangle using opencv findcontour method

thanks a lot. it works

2013-09-16 09:58:59 -0600 commented question Get all points inside a rectangle using opencv findcontour method

I have a bitmap of whitecolor. I have drawn many criss cross lines. All lines are straight and will touch boundaries. These line caused whole plane to split into many regions. I want to detect in which mouse clicked ?

I was amazed to see findcountour method is not able to find some contours. Why is it so ? is there any good way ?

2013-09-15 08:29:33 -0600 received badge  Editor (source)
2013-09-15 08:28:32 -0600 asked a question Get all points inside a rectangle using opencv findcontour method

I want to find all points in the rectangle. But when i use findContour method in opencv, it actually finds points in the lines drawn ( Not points inside the rectangle). I verified using drawcontour method ( even if we use thickness as -1, it draws lines ).

How can i find points inside the smaller rectangle using findContour method ?

//srcMatrix create
Mat srcMat = new Mat();
srcMat.create(100, 100, CvType.8UC3);

// create a canny matrix
Mat mCanny = new Mat();

// Make it to sizeof srcMatrix and 
// make channel to 1
mCanny.create( srcMat.cols(), srcMat.rows, CvType.8UC1) 

// clear it
mCanny.setTo(new Scalar(0));

// draw a border   rectangle on the mcanny
Core.rectangle(mCanny, 
        new Point(0,0),
            new Point(100, 100),
            new Scalar(255));

// draw a rectangle
Core.rectangle(mCanny, 
        new Point(25,25),
            new Point(50, 50),
            new Scalar(255));

// make it binary image
Imgproc.cvtColor(mCanny , mCanny , Imgproc.COLOR_RGB2GRAY);

// make it blur
Imgproc.blur( mCanny, mCanny, new Size(3,3));

//find canny
Imgproc.Canny(mCanny ,mCanny, 2,4); 

/// find Contour
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(mCanny,
            contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
2013-09-13 10:56:45 -0600 asked a question My application runs correctly on emulator but not on my phone

I built a simple application to load a bitmap image and display using opencv. This application runs successfully on an emulator. But when i try to run on mobile phone, it shows unable to start application.

When i tried to install a sample application from opencv sdk ( color-blob-detection.apk ) , it redirects me to google play store to install opencv.

  1. What should i do in my application to ask user to redirect to google store for installing opencv manager.

  2. opencv is absolutely free ? can be downloaded by anyone right ?

2013-09-11 09:54:26 -0600 asked a question program crashes with opencv error while trying to call draw contour

0 down vote favorite

Basically I am trying to draw first contour with a colour. But this program crashes with following error

/////////////////////////////////////////////////////////// 9-11 09:56:38.230: D/dalvikvm(1920): GC_FOR_ALLOC freed 71K, 10% free 2824K/3124K, paused 0ms, total 3ms

09-11 09:56:38.340: D/dalvikvm(1920): GC_FOR_ALLOC freed 379K, 17% free 2958K/3564K, paused 3ms, total 4ms

09-11 09:56:38.360: D/dalvikvm(1920): GC_FOR_ALLOC freed 107K, 10% free 3361K/3696K, paused 2ms, total 3ms

09-11 09:56:38.390: D/dalvikvm(1920): GC_FOR_ALLOC freed 170K, 10% free 3702K/4100K, paused 4ms, total 4ms

09-11 09:56:38.420: E/cv::error()(1920): OpenCV Error: Bad argument (Unknown array type) in cv::Mat cv::cvarrToMat(const CvArr *, bool, bool, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 698

09-11 09:56:38.430: A/libc(1920): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 1920 (pencvratstudy01)

/////////////////////////////////////////////////////////////////////////////

Program is

@Override protected void onCreate(Bundle savedInstanceState) {

Log.i(TAG, "called onCreate");
 super.onCreate( savedInstanceState );

 if (!OpenCVLoader.initDebug()) {
     // Handle initialization error
 }
 setContentView(R.layout.activity_main);


 // load an image from Resource directory
 Mat mMat = new Mat();
 try {
    mMat = Utils.loadResource(this, R.drawable.baby,
                                             Highgui.CV_LOAD_IMAGE_COLOR);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

 // Create result object with correct color
 Mat result = new Mat(); 
 Imgproc.cvtColor(mMat, result, Imgproc.COLOR_RGB2BGRA);


 // create tmpMat object for gray image and blur it
 Mat tmpMat = new Mat();
 Imgproc.cvtColor(result,tmpMat , Imgproc.COLOR_BGR2GRAY);
 Imgproc.blur(tmpMat, tmpMat, new Size(3,3));


 /* find cany of tmpMat */
 Mat canny = new Mat();
 Imgproc.Canny( tmpMat, canny , 2 , 4);

 // find contours
 Mat hierarchy = new Mat();
 List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
 Imgproc.findContours(canny, contours, hierarchy, Imgproc.RETR_EXTERNAL, 
                                                Imgproc.CHAIN_APPROX_SIMPLE);

 // draw contour on mask object   
 Mat mask = new Mat();
 Imgproc.drawContours(mask, contours, 0 , new Scalar(255));


 // create bitmap and draw on imageView
 Bitmap bmp;
 bmp = Bitmap.createBitmap(mask.cols(), mask.rows(), Bitmap.Config.ARGB_8888);
 Utils.matToBitmap(mask, bmp);

 ImageView imgView = (ImageView) findViewById(R.id.sampleImageView);
 imgView.setImageBitmap(bmp);

}