Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Can someone tell me how to convert this C++ code to java? (just 50 lines)

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can someone tell me how to convert this C++ code to java? (just 50 lines)

    #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 .
    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
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Can someone tell me how to convert this C++ code to java? (just 50 lines)

    I've moved this to the Other Programming Languages forum.

    Generally, you don't translate a piece of code line-by-line. Instead, you translate the *intent* of the code as a whole. You ask yourself, "what does this piece of code do?" and then you ask yourself "now how would I do that in Java?"

    So, what does this code do?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can someone tell me how to convert this C++ code to java? (just 50 lines)

    Quote Originally Posted by KevinWorkman View Post
    I've moved this to the Other Programming Languages forum.

    Generally, you don't translate a piece of code line-by-line. Instead, you translate the *intent* of the code as a whole. You ask yourself, "what does this piece of code do?" and then you ask yourself "now how would I do that in Java?"

    So, what does this code do?
    If I knew, I would have already written the Java code for that. specially I don't know about that vector part.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Can someone tell me how to convert this C++ code to java? (just 50 lines)

    If you have no idea what this piece of code does, why do you want to translate it into Java?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can someone tell me how to convert this C++ code to java? (just 50 lines)

    I have already converted the first few lines. Just having a hard time understanding and converting this particular area. I can edit it once it is converted as I am not familiar with C++

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Can someone tell me how to convert this C++ code to java? (just 50 lines)

    I'm not really sure what you're asking for here. Step 1 is to translate this code to English (or whatever natural language you speak natively). What does this code do? Step 2 is to translate that natural language description to Java.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Can someone tell me how to convert this C++ code to java? (just 50 lines)

    Looks like a GUI base or part of one for Windows.

    How much Java do you know?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. please i need help to convert fecn algorithm pseudocode to java code
    By shalini raj in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 26th, 2014, 02:05 PM
  2. How to convert matlab code in Java??
    By Mumpy Zinu in forum Java Theory & Questions
    Replies: 3
    Last Post: November 4th, 2013, 04:09 AM
  3. Math Fromula y=x2+6x+5 how to convert to Java Programming code
    By FreeMan0001 in forum Algorithms & Recursion
    Replies: 10
    Last Post: October 18th, 2013, 10:14 AM
  4. [SOLVED] How to convert this pseudo code into JAVA
    By MUSKAAN DUTT in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2013, 09:36 AM
  5. Convert C/C++ code to Java
    By cristianll in forum What's Wrong With My Code?
    Replies: 13
    Last Post: November 14th, 2009, 02:43 AM

Tags for this Thread