Go to Post Rain? Prepare for Armageddon to strike when you go to St. Louis. Two years in St. Louis. Two years of Tornado scares. Tis the season. - Koko Ed [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 05-02-2017, 14:27
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 38
Lesafian is an unknown quantity at this point
SmartDashboard CameraServer output Flickering

The goal of my code is to be able to switch between vision processing from one camera to another camera.

I have created 2 vision threads, either one or the other is started at one time.
On the SmartDashboard, the camera shows for about a second at 1 fps and 6mbps, then turns off, and repeats. I cannot figure out the issue. Here is the code

Code:
		/*
		 * Sync vision variables from thread to thread.
		 */
		imgLockGoal = new Object();
		imgLockGear = new Object();

		/*
		 * Image used to be processed by a CvSink and outputted through a
		 * CvSource.
		 */
		image = new Mat();

		/*
		 * Camera used to track vision targets on the boiler.
		 */
		cam0 = new UsbCamera("cam0", 0);
		cam0.setResolution(camWidth, camHeight);
		cam0.setFPS(16);

		/*
		 * Camera used to track vision targets on the airship.
		 */
		cam1 = new UsbCamera("cam1", 1);
		cam1.setResolution(camWidth, camHeight);
		cam1.setFPS(16);

		/*
		 * CvSink used to grab and process the image used to output to the
		 * CvSource
		 */
		selectedVid = CameraServer.getInstance().getVideo(cam0);

		/*
		 * CvSource used to output the processed image onto the SmartDashboard
		 * (CameraServer Stream Viewer).
		 */
		outputStream = CameraServer.getInstance().putVideo("Tracking", camWidth, camHeight);

		/*
		 * Vision Thread uses the high goal contour filtering to find the best
		 * targets and help lead the robot to the target destination.
		 */
		visionThreadHighGoal = new VisionThread(cam0, new VisionClass(), pipeline -> {
			selectedVid.grabFrame(image);
			if (pipeline.filterContoursOutput().size() >= 2) {
				//isTargetFound = true;
				Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
				Rect r1 = Imgproc.boundingRect(pipeline.filterContoursOutput().get(1));
				Imgproc.rectangle(image, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height),
						new Scalar(0, 0, 255), 2);
				Imgproc.rectangle(image, new Point(r1.x, r1.y), new Point(r1.x + r1.width, r1.y + r1.height),
						new Scalar(0, 0, 255), 2);
				outputStream.putFrame(image);
				synchronized (imgLockGoal) {
					centerX = (r.x + (r1.x + r1.width)) / 2;
					width = (r.x + r1.x) / 2;
				}
			} else {
				synchronized (imgLockGoal) {
					//isTargetFound = false;
				}
				outputStream.putFrame(image);
			}
		}); visionThreadHighGoal.start();

		// TODO: change filters to specify for gears
		/*
		 * Vision Thread uses the gear contour filtering to find the best
		 * targets and help lead the robot to the target destination.
		 */
		
		visionThreadGear = new VisionThread(cam1, new VisionClass(), pipeline -> {
			selectedVid.grabFrame(image);
			if (pipeline.filterContoursOutput().size() >= 2) {
				isTargetFound = true;
				Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
				Rect r1 = Imgproc.boundingRect(pipeline.filterContoursOutput().get(1));
				Imgproc.rectangle(image, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height),
						new Scalar(0, 0, 255), 2);
				Imgproc.rectangle(image, new Point(r1.x, r1.y), new Point(r1.x + r1.width, r1.y + r1.height),
						new Scalar(0, 0, 255), 2);
				synchronized (imgLockGear) {
					// TODO:
				}
			} else {
				synchronized (imgLockGear) {
					isTargetFound = false;
				}
			}
		});
Thanks!
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 09:43.

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