How to compile Opencv 3.4.1 program in VS 2019 with Opencv 4.1.1?
I've a program written for Opencv 3.4.1 in order to capture image by basler camera and store it in "IplImage*" type of image then show it in Opencv window. I'm using Visual Studio 2019 with Opencv 4.1.1 and when i compiled it it had some errors:
At "static IplImage* s_pCvSrcImg = NULL;" : Missing type specifier-assumed int.Note: C++ does not support the default -int
memcpy(s_pCvSrcImg->imageData, ptrGrabResult->GetBuffer(), ptrGrabResult->GetImageSize());: Identifier " memcpy" cannot be found
And the same errors for cvCanny ,cvShowImage, cvWaitKey in the below Lines Here is the program:
#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 ...
also see here