opencv+SaperaLT++ 多个不需要的窗口与垃圾名称

opencv+SaperaLT++ Multiple unwanted window with Garbage name

本文关键字:窗口 不需要 opencv+SaperaLT++      更新时间:2023-10-16

我正在为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);

不再有随机窗口。