// Initialize camera input
bool CvCaptureCAM_PvAPI::open( int index )
{
    tPvCameraInfo cameraList[MAX_CAMERAS];
    
    tPvCameraInfo  camInfo;
    tPvIpSettings ipSettings;

 
    if (PvInitialize()) {
    }
        //return false;
        
    Sleep(1000);

    //close();
    
    int numCameras=PvCameraList(cameraList, MAX_CAMERAS, NULL);

    if (numCameras <= 0 || index >= numCameras)
        return false;

    Camera.UID = cameraList[index].UniqueId;    

    if (!PvCameraInfo(Camera.UID,&camInfo) && !PvCameraIpSettingsGet(Camera.UID,&ipSettings)) {
		/*
		struct in_addr addr;
		addr.s_addr = ipSettings.CurrentIpAddress;
		printf("Current address:\t%s\n",inet_ntoa(addr));
		addr.s_addr = ipSettings.CurrentIpSubnet;
		printf("Current subnet:\t\t%s\n",inet_ntoa(addr));
		addr.s_addr = ipSettings.CurrentIpGateway;
		printf("Current gateway:\t%s\n",inet_ntoa(addr));
		*/
	}	
	else {
		fprintf(stderr,"ERROR: could not retrieve camera IP settings.\n");
		return false;
	}	


    if (PvCameraOpen(Camera.UID, ePvAccessMaster, &(Camera.Handle))==ePvErrSuccess)
    {
    
        //Set Pixel Format to BRG24 to follow conventions 
        /*Errcode = PvAttrEnumSet(Camera.Handle, "PixelFormat", "Bgr24");
        if (Errcode != ePvErrSuccess)
        {
            fprintf(stderr, "PvAPI: couldn't set PixelFormat to Bgr24\n");
            return NULL;
        }
        */
        tPvUint32 frameWidth, frameHeight, frameSize;
        unsigned long maxSize;
		char pixelFormat[256];
        PvAttrUint32Get(Camera.Handle, "TotalBytesPerFrame", &frameSize);
        PvAttrUint32Get(Camera.Handle, "Width", &frameWidth);
        PvAttrUint32Get(Camera.Handle, "Height", &frameHeight);
        PvAttrEnumGet(Camera.Handle, "PixelFormat", pixelFormat,256,NULL);
        maxSize = 8228;
        //PvAttrUint32Get(Camera.Handle,"PacketSize",&maxSize);
        if (PvCaptureAdjustPacketSize(Camera.Handle,maxSize)!=ePvErrSuccess)
			return false;
        if (strcmp(pixelFormat, "Mono8")==0) {
				grayframe = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 1);
				grayframe->widthStep = (int)frameWidth;
				frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 3);
				frame->widthStep = (int)frameWidth*3;		 
				Camera.Frame.ImageBufferSize = frameSize;
				Camera.Frame.ImageBuffer = grayframe->imageData;   
		}	    
		else if (strcmp(pixelFormat, "Mono16")==0) {
				grayframe = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_16U, 1);
				grayframe->widthStep = (int)frameWidth;	
				frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_16U, 3);
				frame->widthStep = (int)frameWidth*3;
				Camera.Frame.ImageBufferSize = frameSize;
				Camera.Frame.ImageBuffer = grayframe->imageData;
		}	  
		else if	(strcmp(pixelFormat, "Bgr24")==0) {
				frame = cvCreateImage(cvSize((int)frameWidth, (int)frameHeight), IPL_DEPTH_8U, 3);
				frame->widthStep = (int)frameWidth*3;
				Camera.Frame.ImageBufferSize = frameSize;
				Camera.Frame.ImageBuffer = frame->imageData;
		}		
		else
				return false;
        // Start the camera
        PvCaptureStart(Camera.Handle);

        // Set the camera to capture continuously
        if(PvAttrEnumSet(Camera.Handle, "AcquisitionMode", "Continuous")!= ePvErrSuccess)
        {
            fprintf(stderr,"Could not set Prosilica Acquisition Mode\n");
            return false;
        }
        
        if(PvCommandRun(Camera.Handle, "AcquisitionStart")!= ePvErrSuccess)
        {
            fprintf(stderr,"Could not start Prosilica acquisition\n");
            return false;
        }
        
        if(PvAttrEnumSet(Camera.Handle, "FrameStartTriggerMode", "Freerun")!= ePvErrSuccess)
        {
            fprintf(stderr,"Error setting Prosilica trigger to \"Freerun\"");
            return false;
        }
        
        return true;
    }
    fprintf(stderr,"Error cannot open camera\n");
    return false;

}
Beispiel #2
0
int main(int argc, char* argv[])
{
    int err = 0;

    // initialise PvAPI
    if(!PvInitialize())
    {
        int c;
        unsigned long uid = 0;
        bool bList = false;
        bool bGet  = false;
        bool bSet  = false;
        bool bMode = false;
        bool bAddr = false;
        bool bMask = false;
        bool bWay  = false;
        char* vMode = NULL;
        char* vAddr = NULL;
        char* vMask = NULL;
        char* vWay  = NULL;
    
        while ((c = getopt (argc, argv, "lu:gsm:i:n:pw:h?")) != -1)
        {
            switch(c)
            {
                case 'l':
                {
                    bList = true;
                    break;
                }
                case 'u':
                {
                    if(optarg)
                        uid = atol(optarg);
                    
                    break;    
                }
                case 'g':
                {
                    bGet = true;
                    break;
                }
                case 's':
                {
                    bSet = true;
                    break;
                }
                case 'm':
                {
                    bMode = true;
                    if(optarg)
                        vMode = optarg;
                    break;
                }
                case 'i':
                {
                    bAddr = true;
                    if(optarg)
                        vAddr = optarg;
                    break;
                }
                case 'n':
                {
                    bMask = true;
                    if(optarg)
                        vMask = optarg;
                    break;
                }
                case 'w':
                {
                    bWay = true;
                    if(optarg)
                        vWay = optarg;
                    break;
                }
                case '?':
                case 'h':
                {
                    ShowUsage();
                    break;    
                }
                default:
                    break;
            }
        }

        if(uid || bList)
        {

        
            if(bList)
            {
                printf("Searching for cameras ...\n");
                Sleep(2000);
            
                ListCameras();
            }
            else
            {
                printf("Looking for the camera ...\n");
                Sleep(1000);
            
                if(bGet)
                {
                    tPvCameraInfo  camInfo;
                    tPvIpSettings  camConf;
                    struct in_addr addr;

                    if(!PvCameraInfo(uid,&camInfo) &&
                        !PvCameraIpSettingsGet(uid,&camConf))
                    {
                        printf("\t\t\t%s - %s\n",camInfo.SerialString,camInfo.DisplayName);
                        printf("Mode supported:\t\t");
                        if(camConf.ConfigModeSupport & ePvIpConfigPersistent)
                            printf("FIXED ");
                        if(camConf.ConfigModeSupport & ePvIpConfigDhcp)
                            printf("DHCP ");
                        if(camConf.ConfigModeSupport & ePvIpConfigAutoIp)
                            printf("AutoIP");
                        printf("\n");
                        printf("Current mode:\t\t");
                        if(camConf.ConfigMode & ePvIpConfigPersistent)
                            printf("FIXED\n");
                        else
                        if(camConf.ConfigMode & ePvIpConfigDhcp)
                            printf("DHCP&AutoIP\n");
                        else
                        if(camConf.ConfigMode & ePvIpConfigAutoIp)
                            printf("AutoIP\n");

                        addr.s_addr = camConf.CurrentIpAddress;
                        printf("Current address:\t%s\n",inet_ntoa(addr));
                        addr.s_addr = camConf.CurrentIpSubnet;
                        printf("Current subnet:\t\t%s\n",inet_ntoa(addr));
                        addr.s_addr = camConf.CurrentIpGateway;
                        printf("Current gateway:\t%s\n",inet_ntoa(addr));
                    }
                    else
                        fprintf(stderr,"failed to talk to the camera!\n");
                }
                else
                if(bSet)
                {
                    tPvCameraInfo  camInfo;
                    tPvIpSettings  camConf;
                    bool           bApply = false;

                    if(!PvCameraInfo(uid,&camInfo) &&
                        !PvCameraIpSettingsGet(uid,&camConf))
                    {
                        if(bMode && vMode)
                        {
                            unsigned long Mode = 0;                          
                                                 
                            if(!strcasecmp(vMode,"fixed"))
                                Mode = ePvIpConfigPersistent;
                            else
                            if(!strcasecmp(vMode,"dhcp"))
                                Mode = ePvIpConfigDhcp;
                            else
                            if(!strcasecmp(vMode,"autoip"))
                                Mode = ePvIpConfigAutoIp;
                            else
                            {
                                fprintf(stderr,"%s isn't a valid mode\n",vMode);
                                err = 1;
                            }

                            if(Mode)
                            {
                                if(camConf.ConfigModeSupport & Mode)
                                {
                                    camConf.ConfigMode = (tPvIpConfig)Mode;
                                    bApply = true; 
                                }
                                else
                                {
                                    fprintf(stderr,"%s isn't supported by the camera\n",vMode);
                                    err = 1;
                                }
                            }
                        }
                    
                        if(bAddr && vAddr)
                        {
                            camConf.PersistentIpAddr = inet_addr(vAddr); 
                            bApply = true;     
                        }
                      
                        if(bMask && vMask)
                        {
                            camConf.PersistentIpSubnet = inet_addr(vMask);
                            bApply = true;     
                        }
                        
                        if(bWay && vWay)
                        {
                            camConf.PersistentIpGateway = inet_addr(vWay);
                            bApply = true;     
                        }                                                 

                        if(bApply)
                        {
                            if(PvCameraIpSettingsChange(uid,&camConf))
                            {
                                fprintf(stderr,"failed to set the configuration!\n");
                                err = 1;
                            }
                            else
                                printf("Settings changed for %s - %s\n",camInfo.SerialString,camInfo.DisplayName);
                        }
                    }
                    else
                        fprintf(stderr,"failed to talk to the camera!\n");
                }
                else
                {
                    ShowUsage();
                    err = 1;  
                }
            }
        }
        else
        {
            ShowUsage();
            err = 1;  
        }

        // uninitialise the API
        PvUnInitialize();
    }
    else
    {
        err = 1;
        fprintf(stderr,"failed to initialise the API\n");
    }
    
	return err;
}
Beispiel #3
0
int main(int argc, char** argv)
{
  if (argc < 2) {
    printf("Usage: %s 10.68.0.20 [255.255.255.0] [0.0.0.0]\n", argv[0]);
    return 0;
  }

  char nm[] = "255.255.255.0";
  char* netmask = nm;
  if (argc >= 3) {
    netmask = argv[2];
  }

  char gw[] = "0.0.0.0";
  char* gateway = gw;
  if (argc >= 4) {
    gateway = argv[3];
  }

  prosilica::init();
  // Make sure we call prosilica::fini() on exit.
  boost::shared_ptr<void> guard(static_cast<void*>(0), boost::bind(prosilica::fini));

  // Check if camera IP is already set
  char* ip_address = argv[1];
  unsigned long IP = inet_addr(ip_address);
  tPvCameraInfo info;
  tPvIpSettings conf;
  tPvErr err = PvCameraInfoByAddr(IP, &info, &conf);
  if (!err) {
    printf("Camera found at requested IP address:\n");
    printSettings(info, conf);
  }
  else {
    printf("No camera found at %s, trying to change settings of a local camera...\n", ip_address);
    size_t num_cams = prosilica::numCameras();
    if (num_cams == 0) {
      printf("ERROR: No camera detected. Is it plugged in?\n");
      return 1;
    }
    if (num_cams == 2) {
      printf("ERROR: Multiple cameras (%u) found. Do you have more than one plugged in?\n", (unsigned)num_cams);
      return 1;
    }
    
    printf("Detected camera.\n");
    unsigned long uid = prosilica::getGuid(0);
    
    if (PvCameraInfo(uid, &info)) {
      printf("ERROR: could not retrieve camera info.\n");
      return 1;
    }
    if (PvCameraIpSettingsGet(uid, &conf)) {
      printf("ERROR: could not retrieve camera IP settings.\n");
      return 1;
    }
    printf("Original settings:\n");
    printSettings(info, conf);

    printf("Applying new settings...\n");
    conf.ConfigMode = ePvIpConfigPersistent;
    //conf.ConfigMode = ePvIpConfigDhcp;
    conf.CurrentIpAddress = conf.PersistentIpAddr = IP;
    conf.CurrentIpSubnet = conf.PersistentIpSubnet = inet_addr(netmask);
    conf.CurrentIpGateway = conf.PersistentIpGateway = inet_addr(gateway);
    if (PvCameraIpSettingsChange(uid, &conf)) {
      printf("ERROR: Failed to apply the new settings\n");
      return 1;
    }
    printf("New settings:\n");
    printSettings(info, conf);
  }

  return 0;
}
Beispiel #4
0
// Initialize camera input
bool CvCaptureCAM_PvAPI::open( int index )
{
    tPvCameraInfo cameraList[MAX_CAMERAS];

    tPvCameraInfo  camInfo;
    tPvIpSettings ipSettings;


    if (PvInitialize()) {
    }
    //return false;

    Sleep(1000);

    //close();

    int numCameras=PvCameraList(cameraList, MAX_CAMERAS, NULL);

    if (numCameras <= 0 || index >= numCameras)
        return false;

    Camera.UID = cameraList[index].UniqueId;

    if (!PvCameraInfo(Camera.UID,&camInfo) && !PvCameraIpSettingsGet(Camera.UID,&ipSettings))
    {
        /*
        struct in_addr addr;
        addr.s_addr = ipSettings.CurrentIpAddress;
        printf("Current address:\t%s\n",inet_ntoa(addr));
        addr.s_addr = ipSettings.CurrentIpSubnet;
        printf("Current subnet:\t\t%s\n",inet_ntoa(addr));
        addr.s_addr = ipSettings.CurrentIpGateway;
        printf("Current gateway:\t%s\n",inet_ntoa(addr));
        */
    }
    else
    {
        fprintf(stderr,"ERROR: could not retrieve camera IP settings.\n");
        return false;
    }


    if (PvCameraOpen(Camera.UID, ePvAccessMaster, &(Camera.Handle))==ePvErrSuccess)
    {
        tPvUint32 frameWidth, frameHeight;
        unsigned long maxSize;

        // By Default, try to set the pixel format to Mono8.  This can be changed later
        // via calls to setProperty. Some colour cameras (i.e. the Manta line) have a default
        // image mode of Bayer8, which is currently unsupported, so Mono8 is a safe bet for
        // startup.

        monocrome = (PvAttrEnumSet(Camera.Handle, "PixelFormat", "Mono8") == ePvErrSuccess);

        PvAttrUint32Get(Camera.Handle, "Width", &frameWidth);
        PvAttrUint32Get(Camera.Handle, "Height", &frameHeight);

        // Determine the maximum packet size supported by the system (ethernet adapter)
        // and then configure the camera to use this value.  If the system's NIC only supports
        // an MTU of 1500 or lower, this will automatically configure an MTU of 1500.
        // 8228 is the optimal size described by the API in order to enable jumbo frames

        maxSize = 8228;
        //PvAttrUint32Get(Camera.Handle,"PacketSize",&maxSize);
        if (PvCaptureAdjustPacketSize(Camera.Handle,maxSize)!=ePvErrSuccess)
            return false;

        resizeCaptureFrame(frameWidth, frameHeight);

        return startCapture();

    }
    fprintf(stderr,"Error cannot open camera\n");
    return false;

}