Results 1 to 5 of 5
  1. #1
    silvercats is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Default Can someone tell me how to convert this C++ in to Java

    Java Code:
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
     
    using namespace cv;
    using namespace std;
     
    int main( int argc, char** argv )
    {
     Mat src; Mat src_gray;
     src = imread( "airplane1.jpg", 1 );
     resize(src, src, Size(640,480), 0, 0, INTER_CUBIC);
     cvtColor( src, src_gray, CV_BGR2GRAY );
     blur( src_gray, src_gray, Size(3,3) ); 
     namedWindow( "Source", CV_WINDOW_AUTOSIZE );
     imshow( "Source", src );
     
      
     
     // Convex Hull implementation
     Mat src_copy = src.clone();
     Mat threshold_output;
     vector<vector<Point> > contours;
     vector<Vec4i> hierarchy;
     
     // Find contours
     threshold( src_gray, threshold_output, 200, 255, THRESH_BINARY );
     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
     RNG rng;
     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 );
     
     waitKey(0);
     return(0);
    }

    Just this part would be enough .
    Java Code:
    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
     RNG rng;
     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() );
     }

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    9

    Default Re: Can someone tell me how to convert this C++ in to Java

    Hi silvercats,

    Since nobody else has responded thus far I though I should jump in.
    That section of code seems reasonably straight forward. The only thing to be wary of are the calls to the function such as convexHull(), zeros(), etc.. which are not contained in the code above.
    What exactly is the issue you are facing and what have you done/tried so far?

    Regards.

  3. #3
    silvercats is offline Member
    Join Date
    Jun 2014
    Posts
    12
    Rep Power
    0

    Default Re: Can someone tell me how to convert this C++ in to Java

    Quote Originally Posted by Ronin View Post
    Hi silvercats,

    Since nobody else has responded thus far I though I should jump in.
    That section of code seems reasonably straight forward. The only thing to be wary of are the calls to the function such as convexHull(), zeros(), etc.. which are not contained in the code above.
    What exactly is the issue you are facing and what have you done/tried so far?

    Regards.
    Just having a hard time figuring out how to convert this part in to the Java. Vector part is specially strange. Managed t convert others except this.

    Java Code:
    1
    
    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
     RNG rng;
     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() );
     }

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    9

    Default Re: Can someone tell me how to convert this C++ in to Java

    That is a vector containing vectors which contain points. This is declared with the name of 'hull' and a size of contours.size().

    Regards.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Can someone tell me how to convert this C++ in to Java

    If I were to do this I would research the program and find out what it does and how it does it. Then I would
    attempt to write the code in Java to provide the same results. It is possible that some of the C++ features may not
    be in Java libraries and would have to be home grown. But I find little use in simply converting code and not
    understanding how it works. And it will probably rear its head in future debugging efforts.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Convert Java to PHP
    By jop007 in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 08-22-2013, 09:21 AM
  2. How Do I: Convert to Java
    By mexists in forum New To Java
    Replies: 3
    Last Post: 11-29-2011, 02:50 AM
  3. how to convert * into : using java
    By Ricks in forum New To Java
    Replies: 2
    Last Post: 02-02-2010, 04:57 PM
  4. Convert .java to .exe
    By susan in forum New To Java
    Replies: 6
    Last Post: 02-11-2009, 06:47 AM
  5. Convert java to .exe
    By heartysnowy in forum New To Java
    Replies: 13
    Last Post: 11-21-2008, 08:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •