Flipping an image in NIVision

With NIVision I am trying to flip a camera image upside down. I currently have it as an Image type and do not see a NiVision method for rotating or flipping the image. Does anyone know how to flip the camera image in NIVision so I can send it to the CameraServer?

Team 5938 is also looking for a solution to this as well. We have our Microsoft Lifecam mounted upside-down, and our drivers don’t exactly like to go through the terrain with the floor on top. :smiley:

Have you looked at the imaqFlip method in NIVision?

Yes I found the solution. I’ll post a snippet later today for flipping it properly. Thanks for help though!

Can you please post the code that you used to do this? My team has mounted the camera upside down, and I need to flip the image in code. I couldn’t find any documentation on NIVision, and I would appreciate any help.

I am using Java and this is my current command, which is set to run while the robot is disabled. It currently doesn’t correctly send an image to the SmartDashboard and throws and exception occasionally.


package org.usfirst.frc.team1939.robot.commands.camera;

import org.usfirst.frc.team1939.robot.Robot;

import com.ni.vision.NIVision;
import com.ni.vision.NIVision.FlipAxis;
import com.ni.vision.NIVision.Image;
import com.ni.vision.NIVision.ImageType;

import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.vision.USBCamera;

public class CameraUpdater extends Command {

	private USBCamera camera;
	private CameraServer server;

	public CameraUpdater() {
		requires(Robot.camera);
	}

	@Override
	protected void initialize() {
		this.camera = new USBCamera("cam0");
		this.server = CameraServer.getInstance();
		this.camera.startCapture();
	}

	@Override
	protected void execute() {
		Image source = NIVision.imaqCreateImage(ImageType.IMAGE_RGB, 0);
		this.camera.getImage(source);
		Image dest = NIVision.imaqCreateImage(ImageType.IMAGE_RGB, 0);
		NIVision.imaqFlip(dest, source, FlipAxis.CENTER_AXIS);
		this.server.setImage(dest);
	}

	@Override
	protected boolean isFinished() {
		return false;
	}

	@Override
	protected void end() {
	}

	@Override
	protected void interrupted() {
	}
}


Your code is good but center axis needs to be vertical axis( I lied your knit cam wrong here’s a snippet)

camCenter = NIVision.IMAQdxOpenCamera(“cam1”, NIVision.IMAQdxCameraControlMode.CameraControlModeController);
camRight = NIVision.IMAQdxOpenCamera(“cam0”, NIVision.IMAQdxCameraControlMode.CameraControlModeController);
curCam = camCenter;
camera = “center”;
// Img that will contain camera img
frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
// Server that we’ll give the img to
server = CameraServer.getInstance();
server.setQuality(50);
server.setSize(666);

I had this problem too and all you need to do to flip the image 180 degrees is

Image frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);

NIVision.imaqFlip(frame, frame, FlipAxis.HORIZONTAL_AXIS);