Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   General Forum (http://www.chiefdelphi.com/forums/forumdisplay.php?f=16)
-   -   Tracking Rectangles with Java/C++ (http://www.chiefdelphi.com/forums/showthread.php?t=99618)

basicxman 13-01-2012 09:47

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by scottbot95 (Post 1103838)
Would I be correct in assuming that in your example code, Camera is a class you made?

Yes, once we have our tracking code working completely and performing as we'd like, I'll likely post the full source code and an accompanying whitepaper.

wireties 13-01-2012 09:57

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by davidthefat (Post 1100962)
I am able to write the code in Java and port it into C++, but the C++ port will not be tested because I do not want to risk flashing the cRio too much.

Don't worry about it - it will take at least 10000 erase cycle to wear out any one block.

shuhao 13-01-2012 14:23

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by vinnie (Post 1101031)
My team is going to be putting a small Atom powered computer on our robot to do vision processing and other high-level functions. We are going to be using the javacv library to utilize OpenCV in Java. We experimented with vision processing on the cRIO last year, but we found that it was very slow and often lagged the rest of the robot functions. You can easily (I wrote a demo program in ~10 minutes) detect edges/contours with OpenCV and from there decide whether or not the contours make the rectangle you're looking for or not.


How exactly are you guys accomplishing that? Power connection, networking? Not sure how that would be done as we're also thinking of doing that.

JacobGH 13-01-2012 17:18

Re: Tracking Rectangles with Java/C++
 
I'm working on this problem in Java. Am I crazy or do they only make a method available for detcting ellipses and nothing else? Can we, at least, access the values for individual pixels? That way, if they give us nothing else, we could at-least write our own image processing algorithms.

shuhao 13-01-2012 20:33

I believe opencv and the axiscamera's JPEG is your best shot

scottbot95 15-01-2012 15:54

Re: Tracking Rectangles with Java/C++
 
basicxman, I tried the code you suggested and I found that we were finding a ridiculous amount of rectangles(around 42 million). Do you have any idea why this is happening? Also, is there any documentation for the imaqDetectRectangles function?

RufflesRidge 15-01-2012 16:02

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by scottbot95 (Post 1106162)
basicxman, I tried the code you suggested and I found that we were finding a ridiculous amount of rectangles(around 42 million). Do you have any idea why this is happening? Also, is there any documentation for the imaqDetectRectangles function?

You probably want to filter by brightness (luminance) or color (probably in HSL or HSV space) before trying to detect rectangles.

scottbot95 15-01-2012 16:11

Re: Tracking Rectangles with Java/C++
 
I have a sheet of printer paper with the target(with correct proportions) printed on it except where the retro-reflective tape would be, we just printed green. I am then extracting the green plane and going from there.

Ross3098 15-01-2012 17:37

Re: Tracking Rectangles with Java/C++
 
Our team is also trying to figure out how to track the rectangles. Ive been spending a few hours or so looking over nivision.h as well as a few white papers and i seem to have gotten this far:

Code:

       
m_ModifiedImage = m_HSLImage->ThresholdHSL(80,125,45,60,115,130);
       
ImaqImage = m_ModifiedImage->GetImaqImage();

The white paper about the vision targets talks about applying a convex hull operation to really help those rectangles pop out. The main problem I have at the moment is that I have no idea how to apply said operation in C++. Ive found the imaqConvexHull() operation but have no clue how to start it.:(

PriyankP 15-01-2012 17:54

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by Ross3098 (Post 1106248)
I have no idea how to apply said operation in C++. Ive found the imaqConvexHull() operation but have no clue how to start it.:(

This should help you get started! I'll be more helpful more once I see what the code I wrote does when I get it to run on a robot.

basicxman 15-01-2012 18:06

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by scottbot95 (Post 1106162)
basicxman, I tried the code you suggested and I found that we were finding a ridiculous amount of rectangles(around 42 million). Do you have any idea why this is happening? Also, is there any documentation for the imaqDetectRectangles function?

Quote:

Originally Posted by RufflesRidge (Post 1106170)
You probably want to filter by brightness (luminance) or color (probably in HSL or HSV space) before trying to detect rectangles.

Aye, if you generate C code from Vision Assistant it will call imaqThreshold too - something I forgot about in my original snippet.

rudun 15-01-2012 18:14

Re: Tracking Rectangles with Java/C++
 
Would this be how to use the detectRectangles function in java. We looked at the ellipseDetect and I am thinking that hey do the same thing just based on different descriptors.

Code:

    private static final BlockingFunction imaqDetectRectanglesFn =
            NativeLibrary.getDefaultInstance().getBlockingFunction("imaqDetectRectangles");
    static { imaqDetectRectanglesFn.setTaskExecutor(NIVision.taskExecutor); }
    private static Pointer numberOfRectanglesDetected = new Pointer(4);
   
    public static RectangleMatch[] detectRectangles(MonoImage image, RectangleDescriptor rectangleDescriptor,
            CurveOptions curveOptions, ShapeDetectionOptions shapeDetectionOptions,
            RegionOfInterest roi) throws NIVisionException {

        int curveOptionsPointer = 0;
        if (curveOptions != null)
            curveOptionsPointer = curveOptions.getPointer().address().toUWord().toPrimitive();
        int shapeDetectionOptionsPointer = 0;
        if (shapeDetectionOptions != null)
            shapeDetectionOptionsPointer = shapeDetectionOptions.getPointer().address().toUWord().toPrimitive();
        int roiPointer = 0;
        if (roi != null)
            roiPointer = roi.getPointer().address().toUWord().toPrimitive();

        int returnedAddress =
                imaqDetectRectanglesFn.call6(
                image.image.address().toUWord().toPrimitive(),
                rectangleDescriptor.getPointer().address().toUWord().toPrimitive(),
                curveOptionsPointer, shapeDetectionOptionsPointer,
                roiPointer,
                numberOfRectanglesDetected.address().toUWord().toPrimitive());

        try {
            NIVision.assertCleanStatus(returnedAddress);
        } catch (NIVisionException ex) {
            if (!ex.getMessage().equals("No error."))
                throw ex;
        }

        RectanglesMatch[] matches = RectanglesMatch.getMatchesFromMemory(returnedAddress, numberOfRectanglesDetected.getInt(0));
        NIVision.dispose(new Pointer(returnedAddress,0));
        return matches;
    }


Ross3098 15-01-2012 18:20

Re: Tracking Rectangles with Java/C++
 
Quote:

Originally Posted by PriyankP (Post 1106267)
This should help you get started! I'll be more helpful more once I see what the code I wrote does when I get it to run on a robot.

Correct me if I am wrong but does this mean that the integer that the imaqConvexHull() operation returns to is the score? And also I am wondering if the destination image is actually modified within the operation.

Ross3098 15-01-2012 21:29

Re: Tracking Rectangles with Java/C++
 
What is imaqConvexHull() returning to? I have it returning to an integer but what value does the integer have?

Greg McKaskle 15-01-2012 21:45

Re: Tracking Rectangles with Java/C++
 
From the CVI documentation,

Return Value
Type

Description


int On success, this function returns a non-zero value. On failure, this function returns 0. To get extended error information, call imaqGetLastError().


Greg McKaskle


All times are GMT -5. The time now is 18:13.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi