opencv+SaperaLT++ 多个不需要的窗口与垃圾名称
opencv+SaperaLT++ Multiple unwanted window with Garbage name
我正在为Teledyne Dalsa Gige相机编写一个抓取器代码。我正在使用Sapera Lt SDK,并且正在将图像移动到OpenCV进行进一步处理。当我想显示图像时,遗留窗口会留下一个随机名称
我尝试了这个解决方案,但不起作用。
https://www.ridgesolutions.ie/index.php/2013/09/26/opencv-display-window-title-corrupted-and-multiple-windows-show/
#include "conio.h"
#include "math.h"
#include "sapclassbasic.h"
#include "ExampleUtils.h"
#include <opencv2/opencv.hpp>
// Restore deprecated function warnings with Visual Studio 2005
#if defined(_MSC_VER) && _MSC_VER >= 1400
#pragma warning(default: 4995)
#endif
// Static Functions
using namespace cv;
static void XferCallback(SapXferCallbackInfo *pInfo);
static BOOL GetOptions(int argc, char *argv[], char *acqServerName, UINT32 *pAcqDeviceIndex, char *configFileName);
static BOOL GetOptionsFromCommandLine(int argc, char *argv[], char *acqServerName, UINT32 *pAcqDeviceIndex, char *configFileName);
void ExportToOpenCV_Direct(SapBuffer* pSapBuf);
int main(int argc, char* argv[])
{
UINT32 acqDeviceNumber;
char* acqServerName = new char[CORSERVER_MAX_STRLEN];
char* configFilename = new char[MAX_PATH];
printf("Sapera Console Grab Example (C++ version)n");
// Call GetOptions to determine which acquisition device to use and which config
// file (CCF) should be loaded to configure it.
// Note: if this were an MFC-enabled application, we could have replaced the lengthy GetOptions
// function with the CAcqConfigDlg dialog of the Sapera++ GUI Classes (see GrabMFC example)
acqServerName = "Nano-C1940_1";
acqDeviceNumber = 0;
configFilename = "NoFile";
SapAcquisition Acq;
SapAcqDevice AcqDevice;
SapBufferWithTrash Buffers;
SapTransfer AcqToBuf = SapAcqToBuf(&Acq, &Buffers);
SapTransfer AcqDeviceToBuf = SapAcqDeviceToBuf(&AcqDevice, &Buffers);
SapTransfer* Xfer = NULL;
SapView View;
SapLocation loc(acqServerName, acqDeviceNumber);
if (SapManager::GetResourceCount(acqServerName, SapManager::ResourceAcq) > 0)
{
Acq = SapAcquisition(loc, configFilename);
Buffers = SapBufferWithTrash(2, &Acq);
View = SapView(&Buffers, SapHwndAutomatic);
AcqToBuf = SapAcqToBuf(&Acq, &Buffers, XferCallback, &View);
Xfer = &AcqToBuf;
// Create acquisition object
if (!Acq.Create())
goto FreeHandles;
}
else if (SapManager::GetResourceCount(acqServerName, SapManager::ResourceAcqDevice) > 0)
{
if (strcmp(configFilename, "NoFile") == 0)
AcqDevice = SapAcqDevice(loc, FALSE);
else
AcqDevice = SapAcqDevice(loc, configFilename);
Buffers = SapBufferWithTrash(2, &AcqDevice);
View = SapView(&Buffers, SapHwndAutomatic);
AcqDeviceToBuf = SapAcqDeviceToBuf(&AcqDevice, &Buffers, XferCallback, &View);
Xfer = &AcqDeviceToBuf;
// Create acquisition object
if (!AcqDevice.Create())
goto FreeHandles;
}
// Create buffer object
if (!Buffers.Create())
goto FreeHandles;
// Create transfer object
if (Xfer && !Xfer->Create())
goto FreeHandles;
// Create view object
if (!View.Create())
goto FreeHandles;
// Start continous grab
Xfer->Grab();
printf("Press any key to stop grabn");
CorGetch();
// Stop grab
Xfer->Freeze();
if (!Xfer->Wait(5000))
printf("Grab could not stop properly.n");
FreeHandles:
//unregister the acquisition callback
Acq.UnregisterCallback();
// Destroy view object
if (!View.Destroy()) return FALSE;
// Destroy transfer object
if (Xfer && *Xfer && !Xfer->Destroy()) return FALSE;
// Destroy buffer object
if (!Buffers.Destroy()) return FALSE;
// Destroy acquisition object
if (!Acq.Destroy()) return FALSE;
// Destroy acquisition object
if (!AcqDevice.Destroy()) return FALSE;
return 0;
}
static void XferCallback(SapXferCallbackInfo *pInfo)
{
SapView *pView = (SapView *)pInfo->GetContext();
// refresh view
pView->Show();
SapBuffer* Buffer_View = (pView->GetBuffer());
ExportToOpenCV_Direct(Buffer_View);
}
void ExportToOpenCV_Direct(SapBuffer* pSapBuf)
{
if (pSapBuf == NULL)
return;
SapFormat sapFormat = pSapBuf->GetFormat();
int OpenCV_Type = 0;
OpenCV_Type = CV_8UC3;
if (sapFormat != SapFormatUnknown)
{
// Export to OpenCV Mat object using SapBuffer data directly
void* pBuf = NULL;
pSapBuf->GetAddress(&pBuf);
Mat exportImg(pSapBuf->GetHeight(), pSapBuf->GetWidth(), OpenCV_Type, pBuf);
namedWindow("image", 1);
// Display OpenCV Image
imshow("image", exportImg);
pSapBuf->ReleaseAddress(&pBuf);
waitKey(1);
}
}
有人能看出我的错误是什么吗?
我找到了解决方案:
我评论了窗口名称:
//namedWindow("image", 1);
不再有随机窗口。
相关文章:
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- SDL 窗口不会弹出
- 是否有类似std::lower_bound的函数,而不需要排序/分区输入
- 为什么output_editor Concept不需要output_e迭代器标记
- 在除法中不需要四舍五入
- 与C代码相比,为什么C++代码不需要"#define _POSIX_C_SOURCE 200809L"?
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- 将值从另一个数组写入数组,不包括不需要的值 C++
- C++ 写入路径名中包含不需要的空字符的文件
- 是否有必要获取锁并在不需要唤醒线程时通知condition_variable?
- 使用 assimp 加载模型 - 不需要提升?
- 为什么转换函数声明不需要至少一个定义类型说明符
- 返回不需要的值的二叉搜索程序
- 当我不需要数据库中的所有值时,如何部分初始化 c++ 对象?
- C++:用户输入会产生不需要的行为
- 枚举窗口不检测窗口
- 如何在不需要LIBCD.lib的情况下在Visual Studio 6中编译C项目
- 为什么python需要全局关键字而C/C++不需要?
- 使用带有诅咒库的 stdscr 创建窗口,在边框而不是线条中显示不需要的笑脸字符
- opencv+SaperaLT++ 多个不需要的窗口与垃圾名称