У меня есть программа, написанная для Opencv 3.4.1, для захвата изображения камерой Basler и сохранения его в виде изображения «IplImage *», а затем показа в окне Opencv. Я использую Visual Studio 2019 с Opencv 4.1.1, и когда я скомпилировал его, у него были некоторые ошибки:
At "stati c IplImage * s_pCvSrcImg = NULL;" : отсутствует тип Предполагается спецификатор int.Note: C ++ не поддерживает значение по умолчанию -int
memcpy (s_pCvSrcImg-> imageData, ptrGrabResult-> GetBuffer (), ptrGrabResult-> GetImageSize ()); : Не удается найти идентификатор "memcpy"
И те же ошибки для cvCanny , cvShowImage , cvWaitKey в следующих строках
Вот программа:
#define OPENCV
#if defined OPENCV
#include "opencv2/opencv.hpp"
#endif //#if defined OPENCV
#include <conio.h>
// Include files to use the PYLON API.
#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
# include <pylon/PylonGUI.h>
#endif
// Namespace for using pylon objects.
using namespace Pylon;
// Namespace for using cout.
using namespace std;
// Namespace for using GenApi objects.
using namespace GenApi;
// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 1;
#if defined OPENCV
static char s_szCvWindowNameSrc[64] = "Source";
static char s_szCvWindowNameProc[64] = "Processed";
static IplImage* s_pCvSrcImg = NULL; //Source image
static IplImage* s_pCvProcImg = NULL; // Destination image
#endif //#if defined OPENCV
int main(int argc, char* argv[])
{
// The exit code of the sample application.
int exitCode = 0;
// Before using any pylon methods, the pylon runtime must be initialized.
PylonInitialize();
try
{
// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
// Print the model name of the camera.
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
// The parameter MaxNumBuffer can be used to control the count of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5;
// Start the grabbing of c_countOfImagesToGrab images.
// The camera device is parameterized with a default configuration which
// sets up free-running continuous acquisition.
// camera.StartGrabbing( c_countOfImagesToGrab);
camera.StartGrabbing(-1);
#if defined OPENCV
INodeMap& nodemap = camera.GetNodeMap();
CIntegerPtr width(nodemap.GetNode("Width"));
unsigned int uiWidth = (unsigned int)width->GetValue();
CIntegerPtr height(nodemap.GetNode("Height"));
unsigned int uiHeight = (unsigned int)height->GetValue();
// Create OpenCV window for mono8
s_pCvSrcImg = cvCreateImage(cvSize(uiWidth, uiHeight), IPL_DEPTH_8U, 1);
s_pCvProcImg = cvCreateImage(cvSize(uiWidth, uiHeight), IPL_DEPTH_8U, 1);
// for change fps automatically
CBooleanPtr AcquisitionFrameRateEnable(nodemap.GetNode("AcquisitionFrameRateEnable"));
AcquisitionFrameRateEnable->SetValue(true);
#endif //#if defined OPENCV
// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;
// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
int iCount = 0;
bool bQuit = false;
while ( false == bQuit )
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
//cout << iCount << ", " << endl;
// Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded())
{
#if defined OPENCV
DWORD dwTimeStart = GetTickCount();
memcpy(s_pCvSrcImg->imageData, ptrGrabResult->GetBuffer(), ptrGrabResult->GetImageSize());// Retleave image
from SDK
cvCanny(s_pCvSrcImg, s_pCvProcImg, 64, 128); // Edge detection
cvShowImage(s_szCvWindowNameSrc, s_pCvSrcImg); // Show camera image
cvShowImage(s_szCvWindowNameProc, s_pCvProcImg); // Show processed image
cvWaitKey(50); // To keep show cvShowImage
DWORD dwProcTime = GetTickCount() - dwTimeStart;
//cout << "Process Time = " << dwProcTime<< "[ms] img" << ptrGrabResult->GetBlockID() << endl;
printf("\rProcess Time = %ld[ms] img %ld", dwProcTime, (DWORD)ptrGrabResult->GetBlockID());
// change fps automatically. Target is 80% of process time
CFloatPtr AcquisitionFrameRate(nodemap.GetNode("AcquisitionFrameRate"));
double dCamFps = AcquisitionFrameRate->GetValue();
double dTargetFps = 1000.0 / (double)dwProcTime * 0.8;
// Adjustment fps when the camera fps is out of +-50%
if ((dTargetFps*1.5 < dCamFps) || (dTargetFps*0.5 > dCamFps))
{
AcquisitionFrameRate->SetValue(dTargetFps);
printf("\nChange Frame Rate from %5.1f to %5.1f [fps] Process time%d[ms]\n", dCamFps, dTargetFps, dwProcTime);
}
#endif //#if defined OPENCV
#ifdef PYLON_WIN_BUILD
// Display the grabbed image.
//Pylon::DisplayImage(1, ptrGrabResult);
#endif
}
else
{
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
iCount++;
if (::_kbhit())
{
switch (_getch())
{
case 'q': // Quit this program
case 'Q':
bQuit = true;
break;
}
}
}
}
catch (const GenericException &e)
{
// Error handling.
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}
// Comment the following two lines to disable waiting on exit.
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');
// Releases all pylon resources.
PylonTerminate();
return exitCode;
}
Итак, мой вопрос, как исправить эти ошибки и заставить программу компилироваться в VS 2019 с Opencv 4.1.1? Могут ли эти переменные ошибок быть заменены соответствующими в версии Opencv 4.1.1? Если это так, то как называются эти переменные? Огромное спасибо.