我从几台摄像机获得不同的视频流,我希望使用OpenCV imshow并行查看。 imageCapture功能非常简单,单独运行时不会造成任何麻烦。但是,当我运行多个线程时,我会收到Gtk错误。
线程完成如下:
std::thread capture1 (captureImages,hCams.at(0),cSettingsVector.at(0));
std::thread capture2 (captureImages,hCams.at(1),cSettingsVector.at(1));
capture1.join();
capture2.join();
捕捉图像功能:
std::cout << std::endl<< std::endl << "Entering capture function " << std::endl;
int nRet;
char* imgMem;
int memId;
void *pMem;
int bitsPerPixel;
if (cSettings.color == true)
{
bitsPerPixel = 24;
}
else
{
bitsPerPixel = 8;
}
char buffer[256];
sprintf(buffer,"Calling AllocImageMem with handler %i on %s", hCam, cSettings.SN.c_str());
std::cout << buffer << std::endl;
nRet = is_AllocImageMem(hCam, cSettings.AOI.s32Width, cSettings.AOI.s32Height, bitsPerPixel, &imgMem, &memId);
nRet = is_SetImageMem (hCam, imgMem, memId);
nRet = is_CaptureVideo(hCam,IS_DONT_WAIT);
unsigned int iframe(0);
for(;;)
{
nRet = is_GetImageMem(hCam, &pMem);
cv::Mat frame;
if (cSettings.color == true)
{
cv::Mat colorFrame(cv::Size(cSettings.AOI.s32Width, cSettings.AOI.s32Height),CV_8UC3,pMem);
frame = colorFrame;
}
else
{
cv::Mat grayFrame(cv::Size(cSettings.AOI.s32Width, cSettings.AOI.s32Height),CV_8UC1,pMem);
frame = grayFrame;
}
cv::namedWindow(cSettings.SN,cv::WINDOW_OPENGL);
cv::imshow(cSettings.SN,frame);
cv::waitKey(1);
char buffer[128];
sprintf(buffer,"/home/scanner3d/videoCapture/%i-%s.png",iframe,cSettings.SN.c_str());
cv::imwrite(buffer,frame);
std::cout << buffer << std::endl;
iframe ++;
}
sprintf(buffer,"Process with handle %i on %s is done.", hCam, cSettings.SN.c_str());
std::cout << buffer << std::endl;
要将其包装起来,以下是错误:
(4103086391:781): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init()
(4103086391:781): GLib-GObject-WARNING **: cannot register existing type 'GTypeModule'
(4103086391:781): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(4103086391:781): GLib-GObject-CRITICAL **: g_type_register_static: assertion 'parent_type > 0' failed
(4103086391:781): GLib-GObject-CRITICAL **: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
(4103086391:781): GLib-GObject-WARNING **: cannot register existing type 'GTypeModule'
(4103086391:781): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed
(4103086391:781): GLib-GObject-CRITICAL **: g_type_module_set_name: assertion 'G_IS_TYPE_MODULE (module)' failed
Segmentation fault (core dumped)
4103086391是摄像机的唯一标识符,我将其用作窗口名称,因此它出现在错误日志中。
如果我不使用imshow,代码会运行(尽管有其他错误),因为我可以使用imwrite从两个线程编写帧。