Go to Post Also, the judges don't give out awards for money. They give out awards for hard work and effort. - BigJ [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-02-2016, 13:53
jabarabara's Avatar
jabarabara jabarabara is offline
Registered User
FRC #2415 (WiredCats)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2012
Location: Atlanta, Georgia
Posts: 4
jabarabara is an unknown quantity at this point
Problems with Morphology

So, in the past week I've been working on computer vision for this year's competition. I was able to create a binary image by thresholding an image for HSV ranges, but when I try to use morphology dilation I get an error

Code:
        NIVision.Image img, bin, morph;
	NIVision.RawData colorTable;
	
	final NIVision.Range HUE_RANGE = new NIVision.Range(213,255);
	final NIVision.Range SAT_RANGE = new NIVision.Range(217,255);
	final NIVision.Range VIS_RANGE = new NIVision.Range(102,204);
	
        public void robotInit() {
    	    	img = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
    	    	bin = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_U8, 0);
    	    	morph = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_U8, 0); 
    	    	colorTable = new NIVision.RawData();
        }

        public void operatorControl() {
    	    	NIVision.imaqReadFile(img, "/home/lvuser/capture.jpg");
    	    	NIVision.imaqColorThreshold(bin, img, 255, NIVision.ColorMode.HSV, HUE_RANGE, SAT_RANGE, VIS_RANGE);
    	    	NIVision.imaqWriteJPEGFile(bin, "/home/lvuser/bin.jpg", 2000, colorTable);
    	    	NIVision.imaqMorphology(morph, bin, NIVision.MorphologyMethod.DILATE, new NIVision.StructuringElement(3,3,1));
    	    	NIVision.imaqWriteJPEGFile(morph, "/home/lvuser/morph.jpg", 2000, colorTable);
        }
I got this error from the code above:

Code:
VisionException [com.ni.vision.VisionException: imaqError: -1232673104: Unknown error]
	at com.ni.vision.NIVision._imaqMorphology(Native Method)
	at com.ni.vision.NIVision.imaqMorphology(NIVision.java:24502)
	at org.usfirst.frc.team2415.robot.Robot.operatorControl(Robot.java:47)
	at edu.wpi.first.wpilibj.SampleRobot.startCompetition(SampleRobot.java:159)
	at edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:242)
I've already tried searching for the problem to find a solution and couldn't. I don't see what's wrong. Any ideas?
Reply With Quote
  #2   Spotlight this post!  
Unread 26-02-2016, 14:04
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Problems with Morphology

Is there any particular reason you're using NIVision instead of OpenCV?

Last edited by Ozuru : 26-02-2016 at 14:06.
Reply With Quote
  #3   Spotlight this post!  
Unread 26-02-2016, 14:10
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Problems with Morphology

Quote:
Originally Posted by jabarabara View Post
I tried OpenCV at first, but I could never get the code to load the library .
I highly recommend using OpenCV over NIVision.

Also, to load the library:

Code:
    static {
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
Reply With Quote
  #4   Spotlight this post!  
Unread 26-02-2016, 14:15
jabarabara's Avatar
jabarabara jabarabara is offline
Registered User
FRC #2415 (WiredCats)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2012
Location: Atlanta, Georgia
Posts: 4
jabarabara is an unknown quantity at this point
Re: Problems with Morphology

Quote:
Originally Posted by Ozuru View Post
I highly recommend using OpenCV over NIVision.

Also, to load the library:

Code:
    static {
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
I'll try and see if I it will load then and get back to you.

P.S.: sorry for deleting my earlier message. I was trying to rewrite it as a reply to your post, not just another post. Still new
Reply With Quote
  #5   Spotlight this post!  
Unread 26-02-2016, 14:17
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Problems with Morphology

Quote:
Originally Posted by jabarabara View Post
I'll try and see if I it will load then and get back to you.

P.S.: sorry for deleting my earlier message. I was trying to rewrite it as a reply to your post, not just another post. Still new
No problem. I recommend trying to use OpenCV. If you're new to vision tracking, 341's 2012 vision code is required reading: http://www.chiefdelphi.com/media/papers/2676
Reply With Quote
  #6   Spotlight this post!  
Unread 26-02-2016, 19:10
jabarabara's Avatar
jabarabara jabarabara is offline
Registered User
FRC #2415 (WiredCats)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2012
Location: Atlanta, Georgia
Posts: 4
jabarabara is an unknown quantity at this point
Re: Problems with Morphology

Okay, so now I've tried your methon and I get:

Code:
java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1119)
	at org.usfirst.frc.team2415.robot.Robot.<clinit>(Robot.java:13)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:259)
	at edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:204)
with this as code (added the try catch after the first time it failed to get error printed neatly):

Code:
import org.opencv.core.Core;
import edu.wpi.first.wpilibj.SampleRobot;

public class Robot extends SampleRobot {
	
	static{
		try{
			System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		}catch(UnsatisfiedLinkError e){
			e.printStackTrace();
		}
	}
	
    public void robotInit() {}
    
    public void autonomous() {}
    
    public void operatorControl() {}
    
    public void test() {}
}
I tried putting the .so file for opencv in the same directory as the FRCUserProgram on the roboRio, and it still returns this error.
Reply With Quote
  #7   Spotlight this post!  
Unread 26-02-2016, 19:18
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Problems with Morphology

Since you know exactly where the opencv library is located, you have the option of calling System.load("/path/to/library"). Also, make sure that the file is named "libopencv_java310.so", or System.loadLibrary() won't be able to find it.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #8   Spotlight this post!  
Unread 26-02-2016, 19:55
jabarabara's Avatar
jabarabara jabarabara is offline
Registered User
FRC #2415 (WiredCats)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2012
Location: Atlanta, Georgia
Posts: 4
jabarabara is an unknown quantity at this point
Re: Problems with Morphology

Okay I figured out the problem.

1) I didn't have all the necessary dependencies in the directory of the opencv_java"version".so

2) Beforehand, I placed the files in a "/usr/local/lib," and it turns out that I don't have the necessary permissions to load the library from there. Moving the library and its dependencies to the directory of FRCUserProgram.jar fixed that.

I now have OpenCV running on the roboRIO, so I can finally continue Vision Processsing. Thanks for all the help everyone!!!!
Reply With Quote
  #9   Spotlight this post!  
Unread 26-02-2016, 22:07
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Problems with Morphology

Quote:
Originally Posted by jabarabara View Post
Okay I figured out the problem.

1) I didn't have all the necessary dependencies in the directory of the opencv_java"version".so

2) Beforehand, I placed the files in a "/usr/local/lib," and it turns out that I don't have the necessary permissions to load the library from there. Moving the library and its dependencies to the directory of FRCUserProgram.jar fixed that.

I now have OpenCV running on the roboRIO, so I can finally continue Vision Processsing. Thanks for all the help everyone!!!!
Great progress!

I suggest you do not do vision processing on your roboRIO itself. The processing will cause stuttering on your robot's end. I highly recommend sending the frame to the driver's station and then doing processing there in a stand-alone application.
Reply With Quote
  #10   Spotlight this post!  
Unread 27-02-2016, 17:35
euhlmann's Avatar
euhlmann euhlmann is online now
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 312
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Problems with Morphology

Running vision on the DS laptop will result in huge delay times (obviously). We are running vision on-board in a separate thread and it seems to work fine (main robot loop still runs at 50x/sec)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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