Go to Post This is the first (and, if this stuff keeps up, last) time FIRST has allowed high-speed projectiles in years. Please use some common sense, people. - Madison [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 23-01-2017, 16:47
verlander13 verlander13 is offline
Registered User
AKA: Ian
FRC #1025 (IMPIS)
Team Role: Programmer
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Ferndale
Posts: 12
verlander13 is an unknown quantity at this point
Vision

Dos this code work?

package org.usfirst.frc.team1025.robot.subsystems;

import org.opencv.core.Rect;
import org.opencv.imgproc.Imgproc;
import org.usfirst.frc.team1025.robot.GripPipeline;

import com.ctre.CANTalon;

import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.CvSource;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.vision.VisionRunner;
import edu.wpi.first.wpilibj.vision.VisionThread;

public class Vision extends Subsystem {

public static final int IMG_WIDTH = 320;
private static final int IMG_HEIGHT = 240;

private VisionThread visionThread;
UsbCamera camera;
public double centerX = 0.0;
//public RobotDrive drive;

public final Object imgLock = new Object();

public Vision() {
camera = CameraServer.getInstance().startAutomaticCapture() ;
// camera.setResolution(640, 480);
// CvSink cvSink = CameraServer.getInstance().getVideo();
// CvSource cvSource = CameraServer.getInstance().putVideo("Rectangle", IMG_WIDTH, IMG_HEIGHT);


visionThread = new VisionThread(camera, new GripPipeline(), pipeline -> {
if (!pipeline.filterContoursOutput().isEmpty()) {
Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput ().get(0));
synchronized (imgLock) {
centerX = r.x + (r.width / 2);
}
}
});
visionThread.start();

//drive = new RobotDrive(1, 2);
}

public void initDefaultCommand() {

}

public Object getImgLock() {
return imgLock;
}

public double centerX() {
return centerX;
}

public int imageWidth() {
return IMG_WIDTH;
}
public int imageHeight(){
return IMG_HEIGHT;
}
Reply With Quote
 


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 21:40.

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