Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Program crashing when grabbing USB Camera frame + misc comm issues (http://www.chiefdelphi.com/forums/showthread.php?t=134091)

FleventyFive 06-02-2015 19:55

Program crashing when grabbing USB Camera frame + misc comm issues
 
I'm trying to work on vision code or at least displaying a camera feed on the dashboard, but the program crashes on the function where I set the camera server frame. I know about the StartAutomaticCapture function but I'm trying to actually have each frame in memory so I can threshold it or w/e. I have a command that executes this every update time (5 ms or whatever the default is).
Code:

        cam->GetImage(NIframe);

        CameraServer::GetInstance()->SetImage( NIframe );

        Wait(0.1);

This causes the program to crash. The DriverStation says there is no RobotCode until I redeploy it/restart the roborio. The debugger says it is on this line (66) of wpilib's CameraServer.cpp.
Code:

   
    while (start < dataSize - 1) {
      if (data[start] == 0xFF && data[start + 1] == 0xD8) break;
      else start++;
    }

The header file for this command declares these variables
Code:

        USBCamera *cam;
        Threshold *thresh;
        ColorImage *frame;
        Image *NIframe;
        BinaryImage *binaryFrame;

It's been pretty frustrating trying to figure this out. Any ideas? I'm not sure if I'm making an obvious mistake or this is actually an odd issue. Also, even without any vission stuff happening we seem to have communication drops for a second every once in a while, but this might just be low battery. Is my program perhaps too big? It is CommandBassed with like 10 command and 3 subsystems and a few PID loops. Thanks!

bob.wolff68 07-02-2015 18:20

Re: Program crashing when grabbing USB Camera frame + misc comm issues
 
I'm a bit perplexed why you're trying to 'set' the camera frame at all. If you're looking to do image analysis, you'll want to 'get' the frame from the camera and then do analysis on it.

In the case of wanting it on the smartdashboard - that can be accomplished by adding the video pane to the smartdashboard directly. I think this is in the menus or it is a right-click on the dashboard to add it. No programming necessary.

bob

RufflesRidge 07-02-2015 18:25

Re: Program crashing when grabbing USB Camera frame + misc comm issues
 
Quote:

Originally Posted by bob.wolff68 (Post 1439894)
In the case of wanting it on the smartdashboard - that can be accomplished by adding the video pane to the smartdashboard directly. I think this is in the menus or it is a right-click on the dashboard to add it. No programming necessary.

bob

This is not true for the USB camera. You need code to forward the image.

OP, you should check to make sure that you are actually getting a non-null image of non-zero size back from your call to GetImage. If you are calling GetImage every 20ms that's 50FPS which the camera can't provide, I haven't played with this enough to know if that's why your having an issue, but it would be my first suspicion.

FleventyFive 07-02-2015 18:48

Re: Program crashing when grabbing USB Camera frame + misc comm issues
 
Quote:

Originally Posted by RufflesRidge (Post 1439898)
OP, you should check to make sure that you are actually getting a non-null image of non-zero size back from your call to GetImage. If you are calling GetImage every 20ms that's 50FPS which the camera can't provide, I haven't played with this enough to know if that's why your having an issue, but it would be my first suspicion.

This was my guess as well. How to I check if it is non-null? The WPILIB image class has no public functions or attributes at all. It's very confusing... like how can I convert between the Image returned from the USBcamera and the other wpilib image classes like ColorImage (which have public functions like thresholding or w/e)? The AxisCamera class has functions to return these other types of images, but not the USBcamera. Thanks for the help.

Team3266Spencer 07-02-2015 18:59

Re: Program crashing when grabbing USB Camera frame + misc comm issues
 
I know that I have to power cycle the roboRIO when I upload code it can find the camera sometimes.


All times are GMT -5. The time now is 12:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi