Example #1
0
 static struct Pylon::SImageFormat getInFormat(const Pylon::GrabResult&Result) {
   using namespace Pylon;
   struct SImageFormat imageFormat;
   const enum PixelType pixelType= (PixelType) Result.GetPixelType();
   imageFormat.Width =Result.GetSizeX();
   imageFormat.Height=Result.GetSizeY();
   imageFormat.PixelFormat= (Pylon::EPixelType) pixelType;
   imageFormat.LinePitch=IsPacked((Pylon::EPixelType) pixelType)?
     0:
     (7+Result.GetSizeX()*BitPerPixel( (Pylon::EPixelType) pixelType)) >>3;
   
   return imageFormat;
 }
Example #2
0
static P capture_( Pylon::CBaslerGigECamera& camera, Pylon::CBaslerGigECamera::StreamGrabber_t& grabber ) //static Pair capture( Ark::Robotics::Camera::Gige& camera )
{
    /// @todo if color spatial correction implemented, mind the following:
    ///
    /// Runner_Users_manual.pdf, 8.2.2.3:
    ///
    /// If you are using a color camera, you have spatial correction enabled
    /// and you have the frame start trigger mode set to off, you must discard
    /// the first n x 2 lines from the first frame transmitted by the camera
    /// after an acquisition start command is issued (where n is the absolute
    /// value of the current spatial correction parameter setting).
    ///
    /// If you have spatial correction enabled and you have the frame start
    /// trigger mode set to on, you must discard the first n x 2 lines from
    /// each frame transmitted by the camera.
    
    static const unsigned int retries = 10; // quick and dirty: arbitrary
    for( unsigned int i = 0; !done && i < retries; ++i )
    {
        Pylon::GrabResult result;
        //camera.AcquisitionStart.Execute(); // acquire single image (since acquisition mode set so)
        if( !grabber.GetWaitObject().Wait( timeout ) ) // quick and dirty: arbitrary timeout
        {
            std::cerr << "basler-cat: timeout" << std::endl;
            grabber.CancelGrab();
            while( grabber.RetrieveResult( result ) ); // get all buffers back
            if( is_shutdown ) { done = true; }
            return P();
        }
        boost::posix_time::ptime t = boost::get_system_time();
        grabber.RetrieveResult( result );
        if( !result.Succeeded() )
        { 
            std::cerr << "basler-cat: acquisition failed: " << result.GetErrorDescription() << " (" << result.GetErrorCode() << ")" << std::endl;
            std::cerr << "            status: " << ( result.Status() == Pylon::Idle ? "idle" :
                                                     result.Status() == Pylon::Queued ? "queued" :
                                                     result.Status() == Pylon::Grabbed ? "grabbed" :
                                                     result.Status() == Pylon::Canceled ? "canceled" :
                                                     result.Status() == Pylon::Failed ? "failed" : "unknown" ) << std::endl;
            std::cerr << "            run basler-cat --verbose and check your --packet-size settings" << std::endl;
            continue;
        }
        P pair;
        static const snark::cv_mat::serialization::header header = options.get_header();
        switch( header.type )
        {
            case CV_8UC1:
                pair.second = cv::Mat( result.GetSizeY(), result.GetSizeX(), header.type );
                ::memcpy( pair.second.data, reinterpret_cast< const char* >( result.Buffer() ), pair.second.dataend - pair.second.datastart );
                break;
            case CV_8UC3: // quick and dirty for now: rgb are not contiguous in basler camera frame
                pair.second = cv::Mat( result.GetSizeY(), result.GetSizeX(), header.type );
                ::memcpy( pair.second.data, reinterpret_cast< const char* >( result.Buffer() ), pair.second.dataend - pair.second.datastart );
                cv::cvtColor( pair.second, pair.second, CV_RGB2BGR );
                break;
            default: // quick and dirty for now
                std::cerr << "basler-cat: cv::mat type " << options.type << " not supported" << std::endl;
        }            
        set_( pair.first, t, result, camera );
        grabber.QueueBuffer( result.Handle(), NULL ); // requeue buffer
        if( is_shutdown ) { done = true; }
        return pair;
    }
    if( is_shutdown ) { done = true; }
    return P();
}