Ask Your Question
0

How to compile Opencv 3.4.1 program in VS 2019 with Opencv 4.1.1?

asked 2020-03-12 11:59:27 -0600

patrick129 gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

berak gravatar imageberak ( 2020-03-12 12:28:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-03-13 05:26:58 -0600

berak gravatar image

updated 2020-03-13 05:27:47 -0600

the code you're trying to use, is from opencv1.0, long deprecated c-api, and no more available in opencv4

you have to use cv::Mat, and c++ functions from the cv namespace now,

maybe like this (assuming you have a valid ptrGrabResult):

Mat img(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8U, ptrGrabResult->GetBuffer());
Mat proc;   
Canny(img, proc, 64, 128);  // Edge detection
imshow(s_szCvWindowNameSrc, img);    // Show camera image
imshow(s_szCvWindowNameProc, proc); // Show processed image
waitKey(50);    // To keep show cvShowImage
edit flag offensive delete link more

Comments

Thank you so much for your advice! I'll try this way and tell you if it works or not.

patrick129 gravatar imagepatrick129 ( 2020-03-13 05:57:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-12 11:59:27 -0600

Seen: 579 times

Last updated: Mar 13 '20