コード例 #1
1
ファイル: pleora.cpp プロジェクト: Anantak/Pangolin
bool PleoraVideo::GrabNewest( unsigned char* image, bool wait )
{
    PvBuffer *lBuffer0 = NULL;
    PvBuffer *lBuffer = NULL;
    PvResult lOperationResult;

    const uint32_t timeout = wait ? 0xFFFFFFFF : 0;

    PvResult lResult = lStream->RetrieveBuffer( &lBuffer, &lOperationResult, timeout );
    if ( !lResult.IsOK() ) {
        pango_print_warn("Pleora error: %s\n", lResult.GetCodeString().GetAscii() );
        return false;
    }else if( !lOperationResult.IsOK() ) {
        pango_print_warn("Pleora error: %s\n", lOperationResult.GetCodeString().GetAscii() );
        lStream->QueueBuffer( lBuffer );
        return false;
    }

    // We have at least one frame. Capture more until we fail, 0 timeout
    while(true) {
        PvResult lResult = lStream->RetrieveBuffer( &lBuffer0, &lOperationResult, 0 );
        if ( !lResult.IsOK() ) {
            break;
        }else if( !lOperationResult.IsOK() ) {
            lStream->QueueBuffer( lBuffer0 );
            break;
        }else{
            lStream->QueueBuffer( lBuffer );
            lBuffer = lBuffer0;
        }
    }

    bool good = false;

    PvPayloadType lType = lBuffer->GetPayloadType();
    if ( lType == PvPayloadTypeImage )
    {
        PvImage *lImage = lBuffer->GetImage();
        std::memcpy(image, lImage->GetDataPointer(), size_bytes);
        good = true;
    }

    lStream->QueueBuffer( lBuffer );
    return good;
}
コード例 #2
0
ファイル: pleora.cpp プロジェクト: Anantak/Pangolin
bool PleoraVideo::GrabNext( unsigned char* image, bool /*wait*/ )
{
    PvBuffer *lBuffer = NULL;
    PvResult lOperationResult;

    // Retrieve next buffer
    PvResult lResult = lStream->RetrieveBuffer( &lBuffer, &lOperationResult, 1000 );
    if ( !lResult.IsOK() ) {
        pango_print_warn("Pleora error: %s\n", lResult.GetCodeString().GetAscii() );
        return false;
    }

    bool good = false;

    if ( lOperationResult.IsOK() )
    {
        PvPayloadType lType = lBuffer->GetPayloadType();
        if ( lType == PvPayloadTypeImage )
        {
            PvImage *lImage = lBuffer->GetImage();
            std::memcpy(image, lImage->GetDataPointer(), size_bytes);
            good = true;
        }
    } else {
        pango_print_warn("Pleora error: %s\n", lOperationResult.GetCodeString().GetAscii() );
    }

    lStream->QueueBuffer( lBuffer );
    return good;
}
コード例 #3
0
ファイル: pleora.cpp プロジェクト: DapengChalmers/ZSLAM_TX2
T GetParam(PvGenParameterArray* params, const char* name)
{
    typedef typename PleoraParamTraits<T>::PvType PvType;
    PvType* param = dynamic_cast<PvType*>( params->Get(name) );
    if(!param) {
        throw std::runtime_error("Incorrect type");
    }
    T ret;
    PvResult res = param->GetValue(ret);
    if(res.IsFailure()) {
        throw std::runtime_error("Cannot get value: " + std::string(res.GetCodeString().GetAscii()) );
    }
    return ret;
}
コード例 #4
0
ファイル: pleora.cpp プロジェクト: DapengChalmers/ZSLAM_TX2
bool SetParam(PvGenParameterArray* params, const char* name, T val)
{
    typedef typename PleoraParamTraits<T>::PvType PvType;
    PvType* param = dynamic_cast<PvType*>( params->Get(name) );
    if(!param) {
        throw std::runtime_error("Unable to get parameter handle: " + std::string(name) );
    }

    if(!param->IsWritable()) {
        throw std::runtime_error("Cannot set value for " + std::string(name) );
    }

    PvResult res = param->SetValue(val);
    if(res.IsFailure()) {
        throw std::runtime_error("Cannot set value: " + std::string(res.GetCodeString().GetAscii()) );
    }
    return true;
}
コード例 #5
0
ファイル: ImperxStream.cpp プロジェクト: cello623/SAS
int ImperxStream::Connect(const std::string &IP)
{
    PvResult lResult;
    
    // Create an GEV system and an interface.
    PvSystem lSystem;

    // Find all GEV Devices on the network.
    lSystem.SetDetectionTimeout( 2000 );
    lResult = lSystem.Find();
    if( !lResult.IsOK() )
    {
	//Failed to find PvAnything
	printf( "PvSystem::Find Error: %s", lResult.GetCodeString().GetAscii() );
	return -1;
    }

    // Get the number of GEV Interfaces that were found using GetInterfaceCount.
    PvUInt32 lInterfaceCount = lSystem.GetInterfaceCount();

    // Search through interfaces for any devices
    // Check devices for correct target IP
    for( PvUInt32 x = 0; x < lInterfaceCount; x++ )
    {
	// get pointer to each of interface
	PvInterface * lInterface = lSystem.GetInterface( x );

	// Get the number of GEV devices that were found using GetDeviceCount.
	PvUInt32 lDeviceCount = lInterface->GetDeviceCount();

	for( PvUInt32 y = 0; y < lDeviceCount ; y++ )
	{
	    PvDeviceInfo *tDeviceInfo = lInterface->GetDeviceInfo( y );
	    std::string laddress(tDeviceInfo->GetIPAddress().GetAscii());
	    if (!laddress.compare(IP))
	    {
		lDeviceInfo = tDeviceInfo;
		printf( "Interface %i\nMAC Address: %s\nIP Address: %s\nSubnet Mask: %s\n\n",
			x,
			lInterface->GetMACAddress().GetAscii(),
			lInterface->GetIPAddress().GetAscii(),
			lInterface->GetSubnetMask().GetAscii() );
		printf( "Device %i\nMAC Address: %s\nIP Address: %s\nSerial number: %s\n\n",
			y,
			tDeviceInfo->GetMACAddress().GetAscii(),
			tDeviceInfo->GetIPAddress().GetAscii(),
			tDeviceInfo->GetSerialNumber().GetAscii() );
	    }
	}
    }

    // Connect to the last GEV Device found.
    if( lDeviceInfo != NULL )
    {
	printf( "Connecting to %s\n",
		lDeviceInfo->GetMACAddress().GetAscii() );

	lResult = lDevice.Connect( lDeviceInfo );
	if ( !lResult.IsOK() )
	{
	    printf( "Unable to connect to %s\n", 
		    lDeviceInfo->GetMACAddress().GetAscii() );
	}
	else
	{
	    printf( "Successfully connected to %s\n", 
		    lDeviceInfo->GetMACAddress().GetAscii() );
	}
    }
    else
    {
	printf( "No device found\n" );
    }
    // Get device parameters need to control streaming
    PvGenParameterArray *lDeviceParams = lDevice.GetGenParameters();

    return 0;
}
コード例 #6
0
ファイル: ImperxStream.cpp プロジェクト: cello623/SAS
int ImperxStream::Connect()
{
    PvResult lResult;	

    // Create an GEV system and an interface.
    PvSystem lSystem;

    // Find all GEV Devices on the network.
    lSystem.SetDetectionTimeout( 2000 );
    lResult = lSystem.Find();
    if( !lResult.IsOK() )
    {
	printf( "PvSystem::Find Error: %s", lResult.GetCodeString().GetAscii() );
	return -1;
    }

    // Get the number of GEV Interfaces that were found using GetInterfaceCount.
    PvUInt32 lInterfaceCount = lSystem.GetInterfaceCount();

    // Display information about all found interface
    // For each interface, display information about all devices.
    for( PvUInt32 x = 0; x < lInterfaceCount; x++ )
    {
	// get pointer to each of interface
	PvInterface * lInterface = lSystem.GetInterface( x );

	printf( "Interface %i\nMAC Address: %s\nIP Address: %s\nSubnet Mask: %s\n\n",
		x,
		lInterface->GetMACAddress().GetAscii(),
		lInterface->GetIPAddress().GetAscii(),
		lInterface->GetSubnetMask().GetAscii() );

	// Get the number of GEV devices that were found using GetDeviceCount.
	PvUInt32 lDeviceCount = lInterface->GetDeviceCount();

	for( PvUInt32 y = 0; y < lDeviceCount ; y++ )
	{
	    lDeviceInfo = lInterface->GetDeviceInfo( y );
	    printf( "Device %i\nMAC Address: %s\nIP Address: %s\nSerial number: %s\n\n",
		    y,
		    lDeviceInfo->GetMACAddress().GetAscii(),
		    lDeviceInfo->GetIPAddress().GetAscii(),
		    lDeviceInfo->GetSerialNumber().GetAscii() );
	}
    }

    // Connect to the last GEV Device found.
    if( lDeviceInfo != NULL )
    {
	printf( "Connecting to %s\n",
		lDeviceInfo->GetMACAddress().GetAscii() );

	lResult = lDevice.Connect( lDeviceInfo );
	if ( !lResult.IsOK() )
	{
	    printf( "Unable to connect to %s\n", 
		    lDeviceInfo->GetMACAddress().GetAscii() );
	}
	else
	{
	    printf( "Successfully connected to %s\n", 
		    lDeviceInfo->GetMACAddress().GetAscii() );
	}
    }
    else
    {
	printf( "No device found\n" );
    }

    // Get device parameters need to control streaming
    lDeviceParams = lDevice.GetGenParameters();

    return 0;
}
コード例 #7
0
ファイル: LirTest.cpp プロジェクト: USF-COT/LirLogger
bool AcquireImages(CamInfo* cams, int numCams)
{
    int i;
    PvResult result;

    // Initialize Camera System
    PvSystem system;
    system.SetDetectionTimeout(2000);
    result = system.Find();    
    if(!result.IsOK()){
        printf("PvSystem::Find Error: %s", result.GetCodeString().GetAscii());
        return false;
    }

    PvDevice lDevice[numCams];
    PvGenParameterArray *lDeviceParams[numCams];
    PvStream lStream[numCams];
    PvPipeline *lPipeline[numCams];
    for(i=0; i < numCams; i++){
        PvDeviceInfo* lDeviceInfo = NULL;
        PvDeviceInfo* tempInfo;

        // Get the number of GEV Interfaces that were found using GetInterfaceCount.
        PvUInt32 lInterfaceCount = system.GetInterfaceCount();

        // For each interface, check MAC Address against passed address
        for( PvUInt32 x = 0; x < lInterfaceCount; x++ )
        {
            // get pointer to each of interface
            PvInterface * lInterface = system.GetInterface( x );

            // Get the number of GEV devices that were found using GetDeviceCount.
            PvUInt32 lDeviceCount = lInterface->GetDeviceCount();

            for( PvUInt32 y = 0; y < lDeviceCount ; y++ )
            {
                tempInfo = lInterface->GetDeviceInfo( y );
                if(strlen(cams[i].MACAddress) == strlen(tempInfo->GetMACAddress().GetAscii()) && strncmp(cams[i].MACAddress,tempInfo->GetMACAddress().GetAscii(),strlen(cams[i].MACAddress)) == 0){
                    lDeviceInfo = tempInfo;
                    break;
                }
            }
        }

        // If no device is selected, abort
        if( lDeviceInfo == NULL )
        {
            printf( "No device selected.\n" );
            return false;
        }

        // Connect to the GEV Device
        printf( "Connecting to %s\n", lDeviceInfo->GetMACAddress().GetAscii() );
        if ( !lDevice[i].Connect( lDeviceInfo ).IsOK() )
        {
            printf( "Unable to connect to %s\n", lDeviceInfo->GetMACAddress().GetAscii() );
            return false;
        }
        printf( "Successfully connected to %s\n", lDeviceInfo->GetMACAddress().GetAscii() );
        printf( "\n" );

        // Get device parameters need to control streaming
        lDeviceParams[i] = lDevice[i].GetGenParameters();

        // Negotiate streaming packet size
        lDevice[i].NegotiatePacketSize();

        // Open stream - have the PvDevice do it for us
        printf( "Opening stream to device\n" );
        lStream[i].Open( lDeviceInfo->GetIPAddress() );

        // Create the PvPipeline object
        lPipeline[i] = new PvPipeline( &lStream[i] );

        // Reading payload size from device
        PvInt64 lSize = 0;
        lDeviceParams[i]->GetIntegerValue( "PayloadSize", lSize );

        // Set the Buffer size and the Buffer count
        lPipeline[i]->SetBufferSize( static_cast<PvUInt32>( lSize ) );
        lPipeline[i]->SetBufferCount( 16 ); // Increase for high frame rate without missing block IDs

        // Have to set the Device IP destination to the Stream
        lDevice[i].SetStreamDestination( lStream[i].GetLocalIPAddress(), lStream[i].GetLocalPort() );
    }

    PvGenParameterArray *lStreamParams[numCams];
    for(i=0; i < numCams; i++){
        // IMPORTANT: the pipeline needs to be "armed", or started before
        // we instruct the device to send us images
        printf( "Starting pipeline %d\n",i);
        lPipeline[i]->Start();

        // Get stream parameters/stats
        lStreamParams[i] = lStream[i].GetParameters();

        // TLParamsLocked is optional but when present, it MUST be set to 1
        // before sending the AcquisitionStart command
        lDeviceParams[i]->SetIntegerValue( "TLParamsLocked", 1 );

        printf( "Resetting timestamp counter...\n" );
        lDeviceParams[i]->ExecuteCommand( "GevTimestampControlReset" );

        // The pipeline is already "armed", we just have to tell the device
        // to start sending us images
        printf( "Sending StartAcquisition command to device\n" );
        lDeviceParams[i]->ExecuteCommand( "AcquisitionStart" );
    }

    char lDoodle[] = "|\\-|-/";
    int lDoodleIndex = 0;
    PvInt64 lImageCountVal = 0;
    double lFrameRateVal = 0.0;
    double lBandwidthVal = 0.0;
    PvInt64 lPipelineBlocksDropped = 0;

    // Acquire images until the user instructs us to stop
    printf( "\n<press the enter key to stop streaming>\n" );
    //PvBufferWriter writer;
    char filePath[MAXFILEPATH];
    PvUInt32 lWidth = 4096, lHeight = 9250;
    while ( running )
    {
        for(i=0; i < numCams; i++){
            // Retrieve next buffer		
            PvBuffer *lBuffer = NULL;
            PvResult  lOperationResult;
            PvResult lResult = lPipeline[i]->RetrieveNextBuffer( &lBuffer, 1000, &lOperationResult );

            if ( lResult.IsOK() )
            {
                if ( lOperationResult.IsOK() )
                {
                    lStreamParams[i]->GetIntegerValue( "ImagesCount", lImageCountVal );
                    lStreamParams[i]->GetFloatValue( "AcquisitionRateAverage", lFrameRateVal );
                    lStreamParams[i]->GetFloatValue( "BandwidthAverage", lBandwidthVal );
                    lStreamParams[i]->GetIntegerValue("PipelineBlocksDropped", lPipelineBlocksDropped);

                    filePath[0] = '\0';
                    sprintf(filePath,"%s/%s%04X.tif",cams[i].filename,cams[i].prefix,lBuffer->GetBlockID());
                    TIFF *out = TIFFOpen(filePath,"w");
                    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, lWidth);
                    TIFFSetField(out, TIFFTAG_IMAGELENGTH, lHeight);
                    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 1);
                    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
                    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
                    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
                    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
                    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);

                    TIFFWriteEncodedStrip(out,0,lBuffer->GetDataPointer(),lWidth*lHeight);
                    TIFFClose(out);

                    printf( "%d:%s%c Timestamp: %016llX BlockID: %04X %.01f FPS %d DROP %.01f Mb/s\r\n",i,
                            cams[i].prefix,
                            lDoodle[ lDoodleIndex ],
                            lBuffer->GetTimestamp(),
                            lBuffer->GetBlockID(),
                            lFrameRateVal,
                            lPipelineBlocksDropped,
                            lBandwidthVal / 1000000.0 );
                } else {
                    printf("%d: ERROR Code: %s, Description: %s\r\n",i,lOperationResult.GetCodeString().GetAscii(),lOperationResult.GetDescription().GetAscii());
                }
                // We have an image - do some processing (...)
                // VERY IMPORTANT:
                // release the buffer back to the pipeline
                lPipeline[i]->ReleaseBuffer( lBuffer );
                usleep(200);
            }
            else
            {
                // Timeout
                printf( "%d:%s%c Timeout\r\n",i, cams[i].prefix,lDoodle[ lDoodleIndex ]);
            }
        }
        ++lDoodleIndex %= 6;
    }

    //_getch(); // Flush key buffer for next stop
    printf( "\n\n" );

    for(i=0; i < numCams; i++){
        // Tell the device to stop sending images
        printf( "Sending AcquisitionStop command to the device\n" );
        lDeviceParams[i]->ExecuteCommand( "AcquisitionStop" );

        // If present reset TLParamsLocked to 0. Must be done AFTER the 
        // streaming has been stopped
        lDeviceParams[i]->SetIntegerValue( "TLParamsLocked", 0 );

        // We stop the pipeline - letting the object lapse out of 
        // scope would have had the destructor do the same, but we do it anyway
        printf( "Stop pipeline\n" );
        lPipeline[i]->Stop();
        delete lPipeline[i];

        // Now close the stream. Also optionnal but nice to have
        printf( "Closing stream\n" );
        lStream[i].Close();

        // Finally disconnect the device. Optional, still nice to have
        printf( "Disconnecting device\n" );
        lDevice[i].Disconnect();
    }

    return true;
}
コード例 #8
0
ファイル: ThermoCamSingle.cpp プロジェクト: khobbs91/16.831
bool AcquireImages()
{
	PvResult lResult;	
	PvDeviceInfo *lDeviceInfo = NULL;
	PvSystem lSystem;
	PvStream lStream;
	lSystem.SetDetectionTimeout( 20000 );
	lResult = lSystem.Find();
	if( !lResult.IsOK() )
	{
		cout << "PvSystem::Find Error: " << lResult.GetCodeString().GetAscii();
		return -1;
	}
	PvUInt32 lInterfaceCount = lSystem.GetInterfaceCount();
	for( PvUInt32 x = 0; x < lInterfaceCount; x++ )
	{
		PvInterface * lInterface = lSystem.GetInterface( x );
		cout << "Ethernet Interface " << endl;
		cout << "IP Address: " << lInterface->GetIPAddress().GetAscii() << endl;
		cout << "Subnet Mask: " << lInterface->GetSubnetMask().GetAscii() << endl << endl;
		PvUInt32 lDeviceCount = lInterface->GetDeviceCount();
		for( PvUInt32 y = 0; y < lDeviceCount ; y++ )
		{
			lDeviceInfo = lInterface->GetDeviceInfo( y );
			cout << "ThermoCam " << endl;
			cout << "IP Address: " << lDeviceInfo->GetIPAddress().GetAscii() << endl;
		}
	}
	if( lDeviceInfo != NULL )
	{
		cout << "Connecting to " << lDeviceInfo->GetIPAddress().GetAscii() << endl;
		PvDevice lDevice;
		lResult = lDevice.Connect( lDeviceInfo );
		if ( !lResult.IsOK() )
		{
			cout << "Unable to connect to " << lDeviceInfo->GetIPAddress().GetAscii() << endl;
		}
		else
		{
			cout << "Successfully connected to " << lDeviceInfo->GetIPAddress().GetAscii() << endl;
    			lResult = lDevice.NegotiatePacketSize( );
    			if ( !lResult.IsOK() )
    			{
				cout << endl;
        			cout << " Failed to negotiate a packet size setting GevSCPSPacketSize to original value";
        			PvSleepMs( 2500 );
    			}
			cout << endl;
    			cout << "3. Open stream......";
			lResult = lStream.Open( lDeviceInfo->GetIPAddress() );
			if ( !lResult.IsOK() )
			{	
				cout << endl;
				cout << "  Failed to open stream";
				return 0;
			}
			lDevice.SetStreamDestination( lStream.GetLocalIPAddress(), lStream.GetLocalPort() );
			PvInt64 lPayloadSize;
			lDevice.GetGenParameters()->GetIntegerValue( "PayloadSize", lPayloadSize );
			PvBuffer * lBuffer = new PvBuffer();
			lBuffer->Alloc( static_cast<PvUInt32>( lPayloadSize ) );
			PvBuffer *lPtr = NULL; 
			PvImage *lImage = NULL;
			cout << endl;
			cout << "5. Grab one image" << endl;
			lStream.QueueBuffer( lBuffer );
			lDevice.GetGenParameters()->SetIntegerValue( "TLParamsLocked", 1 );
			lDevice.GetGenParameters()->ExecuteCommand( "AcquisitionStart" );
			PvResult lStreamResult;
			lResult = lStream.RetrieveBuffer( &lPtr, &lStreamResult, 10000 );
			lDevice.GetGenParameters()->ExecuteCommand( "AcquisitionStop" );
			lDevice.GetGenParameters()->SetIntegerValue( "TLParamsLocked", 0 );
			PvInt64 lWidth = 0, lHeight = 0;
			PvGenParameterArray *lDeviceParams = lDevice.GetGenParameters();	
			lDeviceParams->GetIntegerValue( "Width", lWidth);
			lDeviceParams->GetIntegerValue( "Height", lHeight);			
			cvNamedWindow("OpenCV: ThermoCam",CV_WINDOW_NORMAL);
			cv::Mat raw_lImage(cv::Size(lWidth,lHeight),CV_8U);
			if ( lResult.IsOK() )
			{
				if ( lStreamResult.IsOK() )
				{
					cout << endl;
					cout << "6. Using RGB Filter";		
					lImage=lPtr->GetImage();
					lPtr->GetImage()->Alloc(lImage->GetWidth(),lImage->GetHeight(),PvPixelMono8);
					cout << "  a. Save the original image into ImageOriginal.bmp";			
					PvBufferWriter lBufferWriter;			
					lBufferWriter.Store(lPtr,"ThermoCam.bmp",PvBufferFormatBMP);
				}
				lImage->Attach(raw_lImage.data,lImage->GetWidth(),lImage->GetHeight(),PvPixelMono8);
				//cv::imshow("OpenCV: ThermoCam",raw_lImage);
				cv::FileStorage fs("ThermoCam.xml",cv::FileStorage::WRITE);		
				fs << "raw_lImage" << raw_lImage;
				fs.release();	
				//if(cv::waitKey(1000) >= 0) break;
				lPtr->Free();
			}
		  	lBuffer->Free();
			lDevice.ResetStreamDestination();
			lStream.Close();
			lDevice.Disconnect();
			return true;
		}
	}
	else
	{
		cout << "No device found" << endl;
	}
	return 0;
}