BOOL CMyVideoOpenCV::CaptureVideoCamera(int nDeviceIndex) { SetVideoType(VIDEO_CAMERA); SetDeviceIndex(nDeviceIndex); m_pCapture = cvCreateCameraCapture(m_nDeviceIndex); // Index = -1 : no matter what camera to use if(!m_pCapture) return FALSE; return TRUE; }
bool PS3EyeCapture::Init(const int deviceNum){ //printf("PS3 Eye cameras connected: %i\n", PS3EyeDriver::GetInstance().GetNumCameras()); SetDeviceIndex(deviceNum); //The requested FPS will be changed to the next-lowest valid framerate if an invalid framerate is requested. bool success = PS3EyeDriver::GetInstance().InitCamera(deviceNum, PS3EyeDriver::RESOLUTION_SETTING::FULL_640_480, 60); if(success){ SetFrameWidth(PS3EyeDriver::GetInstance().GetHeight(deviceNum)); SetFrameHeight(PS3EyeDriver::GetInstance().GetWidth(deviceNum)); rawData = (unsigned char*)malloc(GetFrameWidth()*GetFrameHeight()*3*sizeof(unsigned char)); //cv::Mat frame(cv::Mat(cv::Size(GetFrameWidth(), GetFrameHeight()), CV_8U)); if(useThreadedUpdate) PS3EyeDriver::GetInstance().StartThreadUpdate(); } else{ //printf("Unsuccessful\n"); } return success; }
LFXE_API size_t DeviceManager::InitializeDevices() { LOG_DEBUG(L"Initializing devices"); size_t i = 0; auto config = this->GetLightFXExtender()->GetConfigManager()->GetMainConfig(); this->updateDevicesInterval = config->TimelineUpdateInterval; auto lightpack = make_shared<DeviceLightpack>(config->LightpackHost, config->LightpackPort, config->LightpackKey); this->AddChild(L"Lightpack", lightpack); if (lightpack->Initialize()) { ++i; } auto logitech = make_shared<DeviceLogitech>(); logitech->SetRange(config->LogitechColorRangeOutMin, config->LogitechColorRangeOutMax, config->LogitechColorRangeInMin, config->LogitechColorRangeInMax); this->AddChild(L"Logitech", logitech); logitech->SetRestoreLightsOnNullEnabled(config->LogitechRestoreLightsOnNullEnabled); logitech->SetG110WorkaroundEnabled(config->LogitechG110WorkaroundEnabled); if (logitech->Initialize()) { ++i; } auto corsair = make_shared<DeviceCorsair>(); this->AddChild(L"Corsair", corsair); if (corsair->Initialize()) { ++i; } auto razer = make_shared<DeviceRazer>(); razer->SetHardware(config->RazerUseWithKeyboard, config->RazerUseWithMouse, config->RazerUseWithHeadset, config->RazerUseWithMousepad, config->RazerUseWithKeypad); this->AddChild(L"Razer", razer); if (razer->Initialize()) { ++i; } // Load native LightFX devices this->lightFXLibrary = unique_ptr<LightFX2Proxy>(new LightFX2Proxy(config->AlienwareDllName, config->AlienwareBackupDllName)); if (this->lightFXLibrary->Load()) { LOG_DEBUG(L"Alienware LightFX library found"); LFX_RESULT result; result = this->lightFXLibrary->LFX_Initialize(); if (result == LFX_SUCCESS) { unsigned int numDevices = 0; result = this->lightFXLibrary->LFX_GetNumDevices(&numDevices); if (result == LFX_SUCCESS) { LOG_DEBUG(to_wstring(numDevices) + L" LightFX devices found"); for (unsigned int j = 0; j < numDevices; ++j) { auto lightFX = make_shared<DeviceLightFX>(); lightFX->SetDeviceIndex(j); // Get device name first so we can properly add it to the list of devices char* devDesc = new char[LFX_MAX_STRING_SIZE]; unsigned char devType = 0; if (this->lightFXLibrary->LFX_GetDeviceDescription(j, devDesc, LFX_MAX_STRING_SIZE, &devType) == LFX_SUCCESS) { wstring deviceName = string_to_wstring(devDesc); if (deviceName == L"") { deviceName = L"LightFX " + to_wstring(j); } this->AddChild(deviceName, lightFX); if (lightFX->Initialize()) { ++i; } lightFX->SetDeviceName(deviceName); } else { LOG_ERROR(L"Failed to get the device name of LightFX device " + to_wstring(j)); } LFX_SAFE_DELETE_ARRAY(devDesc); } //TODO: Periodically check for changes (e.g. when a device gets connected or disconnected) } else { LOG_ERROR(L"Failed to check the number of LightFX devices: " + this->lightFXLibrary->LfxResultToString(result)); } } else { LOG_ERROR(L"Failed to initialize LightFX: " + this->lightFXLibrary->LfxResultToString(result)); } } else { LOG_DEBUG(L"Alienware LightFX library not found"); } LOG_INFO(L"Successfully initialized " + to_wstring(i) + L" devices"); // Enable devices where needed if (config->AutoDeviceDetection) { for (size_t i = 0; i < this->GetChildrenCount(); ++i) { auto device = this->GetChildByIndex(i); if (device == nullptr) { LOG_WARNING(L"Device " + device->GetDeviceName() + L" is configured in settings, but was not found in the system"); continue; } if (!device->IsInitialized()) { LOG_WARNING(L"Device " + device->GetDeviceName() + L" cannot be enabled, because was not initialized"); continue; } bool auto_result = device->Enable(); LOG_WARNING(L"Device " + device->GetDeviceName() + L" was automatically set to " + (auto_result ? L"ON" : L"OFF")); } } else { for (pair<wstring, bool> device : config->EnabledDevices) { if (device.second) { auto dev = this->GetChild(device.first); if (dev == nullptr) { LOG_WARNING(L"Device " + device.first + L" is configured in settings, but was not found in the system"); continue; } if (!dev->IsInitialized()) { LOG_WARNING(L"Device " + device.first + L" cannot be enabled, because was not initialized"); continue; } dev->Enable(); } } } return i; }