Compare commits

2 Commits

2 changed files with 61 additions and 21 deletions

View File

@ -43,7 +43,6 @@ target_link_libraries(webcam PRIVATE
engine
framework
opencv_world300
opencv_ts300
extern
Ws2_32

View File

@ -61,16 +61,10 @@ void ProcessWebcamThread::Execute() {
if (temp_pause || !temp_record_frame)
Platform::Get().Sleep(10);
else{
InputVideo->read(*im);
mutex_pause.Lock();
temp_pause = pause;
mutex_pause.Unlock();
if(!temp_pause){
outputVideo->write(*im);
frame_index++;
lutFile.write(reinterpret_cast<const char*>(&current_frame_clock),sizeof(float));
}
outputVideo->write(*im);
lutFile.write(reinterpret_cast<const char*>(&current_frame_clock),sizeof(float));
}
}
__LOG_CAM__ << "THREAD STOPPED "<<videoIndex<<"\n";
@ -109,12 +103,27 @@ HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
return hr;
}
int DisplayDeviceInformation(IEnumMoniker *pEnum)
std::string BstrToString(BSTR bstr)
{
if (!bstr) return std::string();
int len = WideCharToMultiByte(CP_UTF8, 0, bstr, -1, NULL, 0, NULL, NULL);
if (len <= 0) return std::string();
std::string result(len - 1, '\0'); // -1 pour exclure le \0 final
WideCharToMultiByte(CP_UTF8, 0, bstr, -1, &result[0], len, NULL, NULL);
return result;
}
std::vector<int> DisplayDeviceInformation(IEnumMoniker *pEnum)
{
IMoniker *pMoniker = NULL;
int return_id_device = -1;
int counter_device = 0;
std::vector<int> camera_ids;
while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
{
IPropertyBag *pPropBag;
@ -136,10 +145,24 @@ int DisplayDeviceInformation(IEnumMoniker *pEnum)
}
if (SUCCEEDED(hr))
{
printf("%S\n", var.bstrVal);
if (wcscmp(var.bstrVal, L"MMP SDK") != 0 && wcscmp(var.bstrVal, L"Oculus Rift") != 0 && wcscmp(var.bstrVal, L"HTC Vive") != 0)
std::string name = BstrToString(var.bstrVal);
printf("%S\n", var.bstrVal);
__LOG_CAM__<<"FOUND CAM ID "<<counter_device<<" NAME "<<name.c_str()<<"\n";
if (
wcsstr(var.bstrVal, L"MMP SDK") == nullptr &&
wcsstr(var.bstrVal, L"Oculus Rift") == nullptr &&
wcsstr(var.bstrVal, L"HTC Vive") == nullptr &&
wcsstr(var.bstrVal, L"RealSense") == nullptr &&
wcsstr(var.bstrVal, L"OBS") == nullptr
){
camera_ids.push_back(counter_device);
return_id_device = counter_device;
}
__LOG_CAM__<<"RETURN DEVICE ID "<<return_id_device<<"\n";
VariantClear(&var);
}
@ -166,7 +189,8 @@ int DisplayDeviceInformation(IEnumMoniker *pEnum)
pMoniker->Release();
++counter_device;
}
return return_id_device;
return camera_ids;
}
@ -184,7 +208,7 @@ bool Webcam::Open(int width_, int height_) {
height = height_;
int id_device = -1;
std::vector<int> id_devices;
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(hr))
{
@ -193,23 +217,38 @@ bool Webcam::Open(int width_, int height_) {
hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
if (SUCCEEDED(hr))
{
id_device = DisplayDeviceInformation(pEnum);
id_devices = DisplayDeviceInformation(pEnum);
pEnum->Release();
}
CoUninitialize();
}
if (id_device == -1)
if (id_devices.size() == 0)
return false;
InputVideo = new VideoCapture(0);
InputVideo = new VideoCapture();
int device_id = -1;
for (int i = 0; i < id_devices.size(); i++)
{
InputVideo->open(id_devices[i]);
if(InputVideo->isOpened()){
device_id = id_devices[i];
break;
}
}
if(device_id == -1)
return false;
__LOG_CAM__ << "OPEN CAM ID "<<device_id <<"\n";
InputVideo->set(CV_CAP_PROP_FRAME_WIDTH, width);
InputVideo->set(CV_CAP_PROP_FRAME_HEIGHT, height);
InputVideo->set(CAP_PROP_FPS, webcam_fps);
if (!InputVideo->isOpened())
return false;
outputVideo = new VideoWriter;
ReplayInputVideo = new VideoCapture();
@ -232,6 +271,8 @@ void Webcam::Reset(bool _reset_video) {
}
void Webcam::RecordFrame(float _clock) {
if (!thread_process)
return;
thread_process->mutex_record_frame.Lock();
thread_process->record_frame = true;
thread_process->current_frame_clock = _clock;