DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
228 stars 50 forks source link

convert the Pylon image to an Diplib image #54

Closed ahmetmanyasli closed 4 years ago

ahmetmanyasli commented 4 years ago

Component Diplib

Describe the bug When try to convert the Pylon image to an Diplib image I am receiving error from Visual Studio 2017

To Reproduce If applicable, include complete, runnable code to reproduce the behavior.

System information:

My code

// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
    // when c_countOfImagesToGrab images have been retrieved.
    while (camera.IsGrabbing())
    {
        // Wait for an image and then retrieve it. A timeout of 5000 ms is used.
        camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);

        // Image grabbed successfully?
        if (ptrGrabResult->GrabSucceeded())
        {
            // Convert the grabbed buffer to a pylon image.
            formatConverter.Convert(pylonImage, ptrGrabResult);

            // Create an OpenCV image from a pylon image.
            openCvImage = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t *)pylonImage.GetBuffer());
            cvtColor(openCvImage, openCvImage, COLOR_BGR2GRAY);
            dip::Image image(
            static_cast<uint8_t*>(pylonImage.GetBuffer()), // data pointer
            {
                ptrGrabResult->GetWidth(),
                ptrGrabResult->GetHeight()
            },               // width and heigh
                3                                             // 3 channels
            );
            image.SetColorSpace("RGB");
            // Set saveImages to '1' to save images.
            if (saveImages) {
                // Create the current image name for saving.
                std::ostringstream s;
                // Create image name files with ascending grabbed image numbers.
                s << "image_" << grabbedImages << ".jpg";
                std::string imageName(s.str());
                // Save an OpenCV image.

                grabbedImages++;

                openCvImage=measurement_camera1(openCvImage, rondeladiameter, eliptic, eccentricity, burrpercentage, thresh1, camera1calibrasion);
                //imshow("deneme", openCvImage);
                imwrite(imageName, openCvImage);
            }

        }
        else
        {
            //cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
        }
    }

My error Message

Severity    Code    Description Project File    Line    Suppression State
Error   C2664   'dip::Image::Image(const dip::DataSegment &,void *,dip::DataType,dip::UnsignedArray,dip::IntegerArray,const dip::Tensor &,dip::sint,dip::ExternalInterface *)': cannot convert argument 1 from 'uint8_t *' to 'dip::UnsignedArray'  servoqei    c:\users\tcc\source\repos\servoqei\servoqei\pylonframe.cpp  93  
crisluengo commented 4 years ago

@ahmetmanyasli Ah, I see. It is not recognizing the dip::Image constructor form you are using. I just (about an hour ago) pushed a change to master that introduced that form of the constructor. You need to update your copy of the library to the version that is on master now, if you want to use this form of the constructor.

ahmetmanyasli commented 4 years ago

It is working :)