Ask Your Question

Jenang's profile - activity

2020-04-08 05:19:36 -0600 received badge  Notable Question (source)
2018-05-15 23:33:47 -0600 received badge  Popular Question (source)
2017-07-18 01:46:03 -0600 received badge  Notable Question (source)
2016-09-01 07:24:37 -0600 received badge  Notable Question (source)
2016-02-12 14:31:01 -0600 received badge  Popular Question (source)
2015-05-11 06:23:59 -0600 received badge  Popular Question (source)
2014-12-08 01:25:40 -0600 received badge  Nice Question (source)
2013-07-11 23:01:30 -0600 commented question Convex Hull on Java Android OpenCV 2.3

Isn't anyone can help me?

2013-07-11 02:59:40 -0600 asked a question Convex Hull on Java Android OpenCV 2.3

Please help me,

I have a problem for Convex Hull on Android. I use Java and OpenCV 2.3.

Before I made it on Java, I made it on C++ with Visual Studio 2008.

This code can running successfully on C++.

Now, i want to convert it from C++ to Java on Android. And I found error like "force close" when i run it on SDK Android simulator.

This is my code on C++:

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

Canny( img_gray, canny_output, thresh, thresh*2, 3 );
cv::dilate(canny_output, canny_output, cv::Mat(), cv::Point(-1,-1));
showCannyWindow();

findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
drawing = Mat::zeros( canny_output.size(), CV_64F );

/// Find the convex hull object for each contour
vector<vector<Point> > hull ( contours.size() );
for( int i = 0; i < contours.size(); i++ )
  {  convexHull( Mat(contours[i]), hull[i], false );
}

for(size_t i = 0; i < contours.size(); i++){
    drawContours( drawing, hull, i, Scalar(255, 255, 255), CV_FILLED ); // FILL WHITE COLOR
}

And this is my code on Android:

Mat hierarchy = new Mat(img_canny.rows(),img_canny.cols(),CvType.CV_8UC1,new Scalar(0));
    List<Mat> contours =new ArrayList<Mat>();
    List<Mat> hull = new ArrayList<Mat>(contours.size());
    drawing = Mat.zeros(img_canny.size(), im_gray);

    Imgproc.findContours(img_dilasi, contours, hierarchy,Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));

    for(int i=0; i<contours.size(); i++){
        Imgproc.convexHull(contours.get(i), hull.get(i), false);

    }
    for(int i=0; i<contours.size(); i++){
        Imgproc.drawContours(drawing, hull, i, new Scalar(255.0, 255.0, 255.0), 5);
    }

For your info, I did a little modification on Convex Hull at my code. I fill a color inside contour.

This is sample image result on C++:

Binary Image (Before Convex Hull and Fill Color):

image description

After Convex Hull and Fill Color:

image description

Anyone can help me to solve my problem?

I'm very grateful for your help.

2013-03-19 22:50:05 -0600 commented answer Fill Color on ConvexHull

can't you help me with implementation on my source code above?

2013-03-19 00:14:02 -0600 commented question Fill Color on ConvexHull

Anyone can help me?

2013-03-18 23:12:50 -0600 asked a question Fill Color on ConvexHull

Everyone, please help me. I have a problem. I make a Convex Hull detection from this image:

image description

This is a result of Convex Hull detection:

image description

Then, I want to fill a color on area within the boundary of ConvexHull, as shown in the image below:

image description

Is there someone who can help me to make image like above?

I use OpenCV 2.3.

This is a source code:

 #include "stdafx.h" 
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/imgproc/imgproc.hpp"
 #include <iostream>
 #include <stdio.h>
 #include <stdlib.h>

 using namespace cv;
 using namespace std;

 Mat src; Mat src_gray;
 int thresh = 240;
 int max_thresh = 255;
 RNG rng(12345);

 /// Function header
 void thresh_callback(int, void* );

/** @function main */
int main( int argc, char** argv )
 {
   /// Load source image and convert it to gray
   src = imread( "kubis1.jpg", 1 );

   /// Convert image to gray and blur it
   cvtColor( src, src_gray, CV_BGR2GRAY );
   blur( src_gray, src_gray, Size(3,3) );

   /// Create Window
   char* source_window = "Source";
   namedWindow( source_window, CV_WINDOW_AUTOSIZE );
   imshow( source_window, src );

   createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
   thresh_callback( 0, 0 );

   waitKey(0);
   return(0);
 }

 /** @function thresh_callback */
 void thresh_callback(int, void* )
 {
   Mat src_copy = src.clone();
   Mat threshold_output;
   vector<vector<Point> > contours;
   vector<Vec4i> hierarchy;

   /// Detect edges using Threshold
   threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );

   /// Find contours
   findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

   /// Find the convex hull object for each contour
   vector<vector<Point> >hull( contours.size() );
   for( int i = 0; i < contours.size(); i++ )
      {  convexHull( Mat(contours[i]), hull[i], false );
   }

   /// Draw contours + hull results
   Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
   for( int i = 0; i< contours.size(); i++ )
      {
        Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
        drawContours( drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
        drawContours( drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
      }

   /// Show in a window
   namedWindow( "Hull demo", CV_WINDOW_AUTOSIZE );
   imshow( "Hull demo", drawing );
 }
2012-11-13 22:14:03 -0600 commented answer Source code to Closing Holes Leaf Image

OpenCV-2.1.0-win32-vs2008

2012-11-13 07:38:27 -0600 commented answer Source code to Closing Holes Leaf Image

Oh, i'm sorry, i know it now.

Then, I apply the code from you in my code, but this error appears.

error C2664: 'cvFindContours': cannot convert parameter 2 from 'IplImage' to 'CvMemStorage'

error C2228 : left of '.setTo' must have class/struct/union

error C3861 : 'Scalar': identifier not found

error C3861 : 'polylines': identifier not found

error C3861 : 'Scalar': identifier not found

Sorry, i'm newbie, sometimes I don't quite understand about OpenCV. Still need to learn a lot. Hehe.

2012-11-12 10:30:03 -0600 received badge  Editor (source)
2012-11-12 10:24:57 -0600 commented answer Source code to Closing Holes Leaf Image

Please, i don't know what i should do in this part :

// Find binary image of leaf with holes in some way. .....

can't you help me with example in code for that part?

2012-11-12 05:24:56 -0600 received badge  Student (source)
2012-11-12 02:35:32 -0600 asked a question Source code to Closing Holes Leaf Image

Please help me. First, this is original/source picture. (Picture 1)

image description

with canny and morphology, I processing picture from that original picture like this (Picture 2) :

image description

And now, I want to process the image so that it looks like this (Picture 3) :

image description

But I don't know how to make them into images like that (Picture 3). Plese help me. Can you give me the source code to make it like Picture 3 ?

This is my source code (Convert Picture 1 to Picture 2) :

//Area_Daun.cpp : main project file.

#include "stdafx.h"
#include "cxcore.h"
#include "highgui.h"
#include "cv.h"
#include "stdio.h"

using namespace System;

int main()
{
    IplImage* img = NULL;
    IplImage* OpenImg = NULL;

    // load original image
    img = cvLoadImage("kubis2.jpg");

    IplImage* newImg = cvCreateImage (cvGetSize(img), IPL_DEPTH_8U,1);
    IplImage* newImg1 = cvCreateImage (cvGetSize(img), IPL_DEPTH_8U,1);
    IplImage* newImg2 = cvCreateImage (cvGetSize(img), IPL_DEPTH_8U,1);
    CvMat *mat= cvCreateMat(newImg->height, newImg->width, CV_64FC1);
    CvMat *mat1= cvCreateMat(newImg->height, newImg->width, CV_64FC1);
    CvMat *mat2= cvCreateMat(newImg->height, newImg->width, CV_64FC1);

    cvCvtColor(img,newImg,CV_RGB2GRAY);
    cvThreshold(newImg, newImg, 200,255,CV_THRESH_BINARY_INV);
    cvConvert(newImg, mat);

    cvCanny(newImg,newImg1,1,1,3);
    cvConvert(newImg1, mat1);

    cvMorphologyEx( newImg, newImg2, 0, 0, CV_MOP_OPEN, 3);
    cvConvert(newImg2, mat2);

    float putih1 = 0;

    for(int x=0; x<newImg->height; x++){
        for(int y=0; y<newImg->width; y++)
        {
            if (cvmGet (mat,x,y)==255){
                putih1++;
            }
        }
    }

    printf("Luas Daerah Citra / Area Yang Rusak: %.0f\n",putih1);

    cvShowImage( "original", img );
    cvShowImage( "src", newImg );
    cvShowImage( "canny", newImg1 );
    //cvShowImage( "opening", newImg2 );

    cvWaitKey(0);
    return 0;
}