Go to Post You pick the best person for the job whether they are black, white, asian, hispanic, female, or male; NOT so you 'look good' when they publish your team picture in the school paper, but because they can get the job done right, on time, with a passion. - Pavan Dave [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 31-01-2012, 16:20
powerrbill powerrbill is offline
Registered User
FRC #0486
 
Join Date: Jan 2012
Location: Philadelphia area
Posts: 4
powerrbill is an unknown quantity at this point
IMage Width is 0

Our team has been having some trouble with vision... big surprise. Like most people we are having trouble 'getting' the image because the width of the image that the robot is using is 0. This has happened in two drafts of code written by two different programmers, and we have tried writing the compression to 30.

Here is the first draft:
Code:
 
#include "WPILib.h"

				



double Target::GetHorizontalAngle()
{
	double x = m_xPos;
	
	x = atan2(x, 1+cos(28)*-1);
	x = x * 180.0 / 3.14159;
	return x;
}

vector<Target>* Target::FindRectangleTarget()
{
	AxisCamera &camera = AxisCamera::GetInstance("10.4.86.11");
	//AxisCamera &camera = AxisCamera::GetInstance("10.4.86.11");
	camera.WriteCompression(0);
	camera.WriteResolution(AxisCamera::kResolution_320x240);

	camera.WriteBrightness(0);

	
		
		
		
	//threshold default 100,100,100,100,100,100
	
		//camera.GetImage()->Write("binaryImage.jpg")		
	 BinaryImage *binaryimage = camera.GetImage()->ThresholdHSL(105,202,1,22,241,250);
	
	 
	 
	 imaqConvexHull(binaryimage->GetImaqImage(),binaryimage->GetImaqImage(),1);
	 printf("AfterConvex\n");
	 vector<ParticleAnalysisReport> *results = binaryimage->GetOrderedParticleAnalysisReports();
	 delete binaryimage;
	 //results->at(0).center_mass_x_normalized;
	 vector<Target> *returnresults;
	 if(results->size()<0)
	 {
		 return returnresults;
	 }
	 
	 printf("BeforeFoorLoop\n");
	 int b;
	 b= results->size();
	 for(int x=0;x<b;x++)
	 {
		 if(results->at(x).particleArea>1000) //normally 800
		 {
			 Target t;
			 t.m_xPos = results->at(x).center_mass_x_normalized;
			 t.m_ypos = results->at(x).center_mass_y_normalized;
			 returnresults->push_back(t);
		 }
	 }
	 
	 
	 delete results;
	 
	 return returnresults;
	 
}
and here is the second:

Code:
#include "CameraSubsystem.h"
#include "../Robotmap.h"
#include "nivision.h"
#include "Vision/MonoImage.h"
#include "Vision/BinaryImage.h"

#include <algorithm>
#include <math.h>
#include "WPILib.h"
#include "../Commands/CameraCommand.h"

CameraSubsystem::CameraSubsystem() : Subsystem("CameraSubsystem") {
	
}
    
void CameraSubsystem::InitDefaultCommand() {
	SetDefaultCommand(new CameraCommand);
	// Set the default command for a subsystem here.
	//SetDefaultCommand(new MySpecialCommand());
}
void CameraSubsystem::Track()
{
	AxisCamera &camera = AxisCamera::GetInstance("10.4.86.11");

		camera.WriteCompression(0);
		camera.WriteResolution(AxisCamera::kResolution_320x240);	
		camera.WriteBrightness(30);
	ColorImage *colorimage;
		
	colorimage = camera.GetImage();
	double size; 
	size = colorimage->GetWidth();
	if (size==0)//the size is zero
	{
		printf("size is zero");
	}
	BinaryImage *binaryimage = colorimage->ThresholdHSL(100,100,100,100,100,100);
}
and both have the same error: 0xBFF60406 in ColorImage.cpp line 37.

Any help would be greatly appreciated
Reply With Quote
  #2   Spotlight this post!  
Unread 01-02-2012, 00:30
enrique's Avatar
enrique enrique is offline
Registered User
FRC #1251 (Tech Tigers)
Team Role: Electrical
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Florida
Posts: 87
enrique will become famous soon enough
Send a message via Yahoo to enrique
Re: IMage Width is 0

I had this happen recently.
I did 2 things.
#1 Reset the camera to factory settings.
#2 Change the camera.WriteBrightness(0); to camera.WriteBrightness(20);
Reply With Quote
  #3   Spotlight this post!  
Unread 03-02-2012, 13:48
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: IMage Width is 0

I see a few issues here.

1. brightness needs to be set non-zero - 50 may even be a nice number. You can try different values by going to the webpage for the camera and experimenting but in the real deal, you'll need to set this in the pits based upon regional lighting.

2. Doing the AxisCamera::GetInstance() followed by setting settings for each image/trial is likely a bad thing for the camera. The settings are not sent to the camera right away as they are sent en-batch in a separate task. You're MUCH more advised to do your GetInstance and settings at initialization time and simply use the instance you get back throughout your code in autonomous and teleop (or at least one for each). Also, you may want to do what many are doing....after setting the settings, do a Wait(3.0); (I'm not sure that 3 seconds is required, but that's what I've seen a lot of and haven't experimented to refute the number)

3. You have a line where you get the binary image by using:
Code:
  BinaryImage *binaryimage = camera.GetImage()->ThresholdHSL(105,202,1,22,241,250);
There is a memory leak here. camera.GetImage() returns you a ColorImage* which **IT ALLOCATED** -- it is your responsibility to delete it after you are done with it. So you'll need a temp variable in there to allow for that.

4. With the following code block I am seeing some issues...
Code:
	 vector<Target> *returnresults;
	 if(results->size()<0)
	 {
		 return returnresults;
	 }
a) 'results->size() < 0' ... I don't think this is even possible. Did you mean 'results->size() <= 0' which would check to see if there are NO PARTICLES ?
b) if you wind up in the if-block, you return 'returnresults' which is a pointer that is uninitialized. Gonna cause you issues. I'd suggest maybe prepping the caller that you might return NULL in this case and that NULL is their signal that you got nothing in terms of particles.

5. Lastly - when you do return 'returnresults' to the caller, you must be careful and have the caller delete returnresults (and take care of each item in the vector<> deleting them along the way iteratively prior to deletion of the vector* itself).

bob

Quote:
Originally Posted by powerrbill View Post
Our team has been having some trouble with vision... big surprise. Like most people we are having trouble 'getting' the image because the width of the image that the robot is using is 0. This has happened in two drafts of code written by two different programmers, and we have tried writing the compression to 30.

Here is the first draft:
Code:
 
#include "WPILib.h"

				



double Target::GetHorizontalAngle()
{
	double x = m_xPos;
	
	x = atan2(x, 1+cos(28)*-1);
	x = x * 180.0 / 3.14159;
	return x;
}

vector<Target>* Target::FindRectangleTarget()
{
	AxisCamera &camera = AxisCamera::GetInstance("10.4.86.11");
	//AxisCamera &camera = AxisCamera::GetInstance("10.4.86.11");
	camera.WriteCompression(0);
	camera.WriteResolution(AxisCamera::kResolution_320x240);

	camera.WriteBrightness(0);

	
		
		
		
	//threshold default 100,100,100,100,100,100
	
		//camera.GetImage()->Write("binaryImage.jpg")		
	 BinaryImage *binaryimage = camera.GetImage()->ThresholdHSL(105,202,1,22,241,250);
	
	 
	 
	 imaqConvexHull(binaryimage->GetImaqImage(),binaryimage->GetImaqImage(),1);
	 printf("AfterConvex\n");
	 vector<ParticleAnalysisReport> *results = binaryimage->GetOrderedParticleAnalysisReports();
	 delete binaryimage;
	 //results->at(0).center_mass_x_normalized;
	 vector<Target> *returnresults;
	 if(results->size()<0)
	 {
		 return returnresults;
	 }
	 
	 printf("BeforeFoorLoop\n");
	 int b;
	 b= results->size();
	 for(int x=0;x<b;x++)
	 {
		 if(results->at(x).particleArea>1000) //normally 800
		 {
			 Target t;
			 t.m_xPos = results->at(x).center_mass_x_normalized;
			 t.m_ypos = results->at(x).center_mass_y_normalized;
			 returnresults->push_back(t);
		 }
	 }
	 
	 
	 delete results;
	 
	 return returnresults;
	 
}
and here is the second:

Code:
#include "CameraSubsystem.h"
#include "../Robotmap.h"
#include "nivision.h"
#include "Vision/MonoImage.h"
#include "Vision/BinaryImage.h"

#include <algorithm>
#include <math.h>
#include "WPILib.h"
#include "../Commands/CameraCommand.h"

CameraSubsystem::CameraSubsystem() : Subsystem("CameraSubsystem") {
	
}
    
void CameraSubsystem::InitDefaultCommand() {
	SetDefaultCommand(new CameraCommand);
	// Set the default command for a subsystem here.
	//SetDefaultCommand(new MySpecialCommand());
}
void CameraSubsystem::Track()
{
	AxisCamera &camera = AxisCamera::GetInstance("10.4.86.11");

		camera.WriteCompression(0);
		camera.WriteResolution(AxisCamera::kResolution_320x240);	
		camera.WriteBrightness(30);
	ColorImage *colorimage;
		
	colorimage = camera.GetImage();
	double size; 
	size = colorimage->GetWidth();
	if (size==0)//the size is zero
	{
		printf("size is zero");
	}
	BinaryImage *binaryimage = colorimage->ThresholdHSL(100,100,100,100,100,100);
}
and both have the same error: 0xBFF60406 in ColorImage.cpp line 37.

Any help would be greatly appreciated
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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 14:27.

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