I’m having trouble with the call to GetImage.
I’m getting a connection to the camera because if I unhook the cat 5 I get a connect error on the “AxisCamera::GetInstance(“10.12.51.11”);” line. but when when I call GetImage, I get nothing. The width is 0 and IsFreshImage is always false. Am I missing something?
if (m_CamEnabled)
{
int iWidth = 0;
AxisCamera &m_camera = AxisCamera::GetInstance(“10.12.51.11”);
HSLImage *image = m_camera.GetImage();
Error &err = m_camera.GetError();
if (err.GetLineNumber() != 0)
{
printf("AxisCamera error number %f
", err.GetLineNumber());
printf(err.GetMessage());
}
if (telePeriodicLoops < 2)
{
m_camera.WriteResolution(AxisCamera::kResolution_320x240);
m_camera.WriteCompression(20);
m_camera.WriteBrightness(0);
}
//if (m_camera.IsFreshImage())
//{
// get the camera image
//m_camera.IsFreshImage();
iWidth = image->GetWidth();
if (iWidth > 0)
{
Set your resolution, brightness, and compression before getting any images. Shouldn’t be some major failure point, but…good practice.
Also, I thought that GetImage returned a ColorImage and while HSLImage is related, I’d give a shot at going to the basics that way.
Otherwise, I might suspect config issues - have you tried NI Vision assistant and is it able to grab images?
Lastly - after looking once again - I would suggest using a standard while(isOperatorControl()) {} and place your if (isFreshImage()) inside there. Remember, this is a realtime gig and while your desktop is faster than the cRio, the cRio is 400MHz and so it’ll crank through the camera items very quickly. It is possible that after gaining access to the camera, it isn’t ready for you to grab an image. I’d suggest sometime like:
...OperatorControl() {
int iWidth = 0;
Error &err;
ColorImage *image;
AxisCamera &m_camera = AxisCamera::GetInstance("10.12.51.11");
m_camera.WriteResolution(AxisCamera::kResolution_3 20x240);
m_camera.WriteCompression(20);
m_camera.WriteBrightness(0);
while (isOperatorControl())
{
if (m_camera.isFreshImage())
{
image = m_camera.GetImage();
err = m_camera.GetError();
if (err.GetLineNumber() != 0)
{
// Might this supposed to be err.GetCode() for a code value?
// Not going to fix the problem - but will be more informative I think.
printf("AxisCamera error number %f
", err.GetLineNumber());
printf(err.GetMessage());
}
else
{
iWidth = image->GetWidth();
}
delete image;
}
}
return;
}
This will test to make sure that you’re REALLY waiting on the camera to become ready and grabbing an image, checking errors, and width etc. If you have are actively debugging, I’d breakpoint on ‘iWidth=’ line or do a printf() or something to alert yourself that you really did get a valid image at some point.
bob
P.S. This is being typed @ work - no compilers involved. Likely has minor issues or more…
I am assuming that the camera is plugged in via Ethernet to the wireless bridge. If it is plugged in to the second Ethernet port on the cRIO then the IP adress should be 192.168.0.90 I believe. Did you use the utility that was provided with the other various LabView utilities that configures the camera? If not then that might be your issue. Did you connect to the IP address from the computer to make sure that the camera is actually streaming the video? Try using the function imaqWriteBMP (I think that is what it is called) in nivision.h, this should also help to make sure that it is taking in data. You didn’t really provide enough info as to what the problem might be, it could be a hardware issue… It took me about a week to get all the vision processing done in C++, nivision.h isn’t very fun to work with.
The FRC Dashboard does see the image and vision was able to grab images. I assume vision uses the same api. this is a crio II and the camera is plugged into the router. as far as I can tell I am setting the settings before calling get image. I’m using the periodic style code. (“void TeleopPeriodic(void)”). I was planning to connect to the camera and set the settings in the “void TeleopInit(void)”, and then do image processing from TeleopPeriodic. This should have the same affect. I guess I could do the “while (isOperatorControl())”
I will definitely do a new project just with that code to see what happens.
I guess I can try that imaqWriteBMP and write to the “harddrive” and see what happens too.
Ok I tried this code, but isFreshImage is always false.
also. I had to use HSLImage *image; instead of ColorImage *image; in order to compile with no type mismatch.
I’m not familiar with console output for such a situation and I can’t tell what code you’re using to get this output either. But I don’t see any errors. Obviously the ‘override me’, but no errors…is there something in particular that is suspicious in your view of this?
Can someone with more console output experience weigh in?