Go to Post You know you have FIRST Kickoff fever when you know when Kickoff is but not Christmas. - Jacob.B [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-01-2015, 17:49
vps vps is offline
Registered User
FRC #3021 (The Agency)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2011
Location: United States
Posts: 30
vps is an unknown quantity at this point
WPILib vision error in ColorImage.cpp and BinaryImage.cpp

Hi yall,
I am playing around with WPILib for vision and all I am doing is thresholding a colorimage acquired from the axis camera into a binaryimage and then getting a particleanalysisreport vector from that image. Then, I simply find out the center of mass of the two particles.

All I am doing is calling for print statements for NumOfParticles(), IsTargetFound(), and CenterOfMass() in my autonomous code (Functions defined below).

All of these are outputting exactly what I expect, but, after about 5 seconds, errors alternate between
"Error on line 37 of ColorImage.cpp: 0: ImaqThreshold error" and
"Error on line 30 of BinaryImage.cpp: 0: Error counting particles".

Then, autonomous stops and driver station shows "No Robot Code".

Here's the code of my Vision class:
Code:
//Vision.h
#pragma once

#include "WPILib.h"
#include <vector>

namespace Subsystems {
	class Vision {
	private:
		AxisCamera* axis;
		ColorImage* ci;
		BinaryImage* bi;
		std::vector<ParticleAnalysisReport>* particles;
		void GetImage();
	public:

		Vision();
		~Vision();
                int NumOfParticles();
		bool IsTargetFound();
		int CenterOfMass();
	};
}
Code:
//Vision.cpp
#include "Vision.h"

namespace Subsystems {

	Vision::Vision() {                    //note the vector "particles" is not initialized. I didn't find a need to
		axis = new AxisCamera("10.30.21.11");
		axis->WriteResolution(AxisCamera::kResolution_160x120);
		ci = new ColorImage(ImageType::IMAQ_IMAGE_RGB);
		bi = new BinaryImage();
	 }
	 Vision::~Vision() {
		delete axis;
		delete ci;
		 delete bi;
	 }

	//private functions
	void Vision::GetImage() {
		ci = axis->GetImage();
		bi = ci->ThresholdRGB(0,255,175,255,0,255);	//use green LED

 	}

	//public functions
	int Vision::NumOfParticles() {
		GetImage();
		return bi->GetNumberParticles();
	}
	bool Vision::IsTargetFound() {
		if(NumOfParticles()==2) return true;
		return false;
	}
	int Vision::CenterOfMass() {
		if(!IsTargetFound()) return false;
		particles = bi->GetOrderedParticleAnalysisReports(); //this is a pointer to a vector

		int center_mass = ((*particles)[0].center_mass_x+ (*particles)[1].center_mass_x)/2;
				//the center of mass of the two vision targets
		particles->clear();			//clear vector
		return center_mass;
	}
}
Why do you think the program just stops like that with these strange errors?
Quote:
Error on line 37 of ColorImage.cpp: 0: ImaqThreshold error
at /home/lvuser/FRCUserProgram() [0x1a8e8]
at /home/lvuser/FRCUserProgram() [0x1a964]
at /home/lvuser/FRCUserProgram() [0x1084c]
at /home/lvuser/FRCUserProgram() [0x10878]
at /home/lvuser/FRCUserProgram() [0x108b8]
at /home/lvuser/FRCUserProgram() [0x11124]
at /home/lvuser/FRCUserProgram() [0x1a350]
at /home/lvuser/FRCUserProgram() [0x11570]
at /home/lvuser/FRCUserProgram() [0x1057c]
at __libc_start_main

Error on line 30 of BinaryImage.cpp: 0: Error counting particles
at /home/lvuser/FRCUserProgram() [0x1b694]
at /home/lvuser/FRCUserProgram() [0x10888]
at /home/lvuser/FRCUserProgram() [0x108b8]
at /home/lvuser/FRCUserProgram() [0x11124]
at /home/lvuser/FRCUserProgram() [0x1a350]
at /home/lvuser/FRCUserProgram() [0x11570]
at /home/lvuser/FRCUserProgram() [0x1057c]
at __libc_start_main
  #2   Spotlight this post!  
Unread 19-01-2015, 18:08
vps vps is offline
Registered User
FRC #3021 (The Agency)
Team Role: Programmer
 
Join Date: Mar 2013
Rookie Year: 2011
Location: United States
Posts: 30
vps is an unknown quantity at this point
Re: WPILib vision error in ColorImage.cpp and BinaryImage.cpp

Here is line 37 of the ColorImage.cpp

Code:
 BinaryImage * ColorImage::ComputeThreshold(ColorMode colorMode,
                 int low1, int high1,
                 int low2, int high2,
                 int low3, int high3)
 {
         BinaryImage *result = new BinaryImage();
         Range range1 = {low1, high1},
                 range2 = {low2, high2},
                 range3 = {low3, high3};
         
         int success = imaqColorThreshold(result->GetImaqImage(),   
m_imaqImage, 1, colorMode, &range1, &range2, &range3);

         wpi_imaqAssert(success, "ImaqThreshold error"); 
//here's the assert that's producing the error. What can I do to fix this?
         return result;
}
Note that an assert is failing. What can I do to rectify this on my end?
Thanks.
  #3   Spotlight this post!  
Unread 19-01-2015, 18:35
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: WPILib vision error in ColorImage.cpp and BinaryImage.cpp

That's an obnoxious assert.

But the problem is likely one of two things, you end up running out of memory or you are passing in an image of zero size (likely the second one). Check that your image has a size before you do any operations on it.
Closed Thread


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 02:45.

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