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

        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:

VisionException [ imaqError: -1232673104: Unknown error]
	at Method)
	at org.usfirst.frc.team2415.robot.Robot.operatorControl(
	at edu.wpi.first.wpilibj.SampleRobot.startCompetition(
	at edu.wpi.first.wpilibj.RobotBase.main(

I’ve already tried searching for the problem to find a solution and couldn’t. I don’t see what’s wrong. Any ideas?

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

I highly recommend using OpenCV over NIVision.

Also, to load the library:

    static {

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 :stuck_out_tongue:

No problem. I recommend trying to use OpenCV. If you’re new to vision tracking, 341’s 2012 vision code is required reading:

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

java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path
	at java.lang.ClassLoader.loadLibrary(
	at java.lang.Runtime.loadLibrary0(
	at java.lang.System.loadLibrary(
	at org.usfirst.frc.team2415.robot.Robot.<clinit>(
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at edu.wpi.first.wpilibj.RobotBase.main(

with this as code (added the try catch after the first time it failed to get error printed neatly):

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

public class Robot extends SampleRobot {
		}catch(UnsatisfiedLinkError e){
    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.

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 “”, or System.loadLibrary() won’t be able to find it.

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.

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)