basler / pypylon-samples

BSD 3-Clause "New" or "Revised" License
40 stars 14 forks source link

Conversion from mono12packed without grabResult (using raw bytes) #8

Open Niv-R opened 4 months ago

Niv-R commented 4 months ago

Use Case My use case can benefit from performing the conversion from mono12packed in another Python process.

Problem I've attempted to use ImageFormatConverter.Convert, and the docstring details the parameters as follows:

"""
Parameters
        ----------
        * `pDestinationBuffer` :  
            The pointer to the buffer of the destination image.  
        * `destinationBufferSizeBytes` :  
            The size of the buffer of the destination image.  
        * `pSourceBuffer` :  
            The pointer to the buffer of the source image.  
        * `sourceBufferSizeBytes` :  
            The size of the buffer of the source image.  
        * `sourcePixelType` :  
            The pixel type of the source image.  
        * `sourceWidth` :  
            The number of pixels in a row in the source image.  
        * `sourceHeight` :  
            The number of rows in the source image.  
        * `sourcePaddingX` :  
            The number of extra data bytes at the end of each row. The default value is
            usually 0.  
        * `sourceOrientation` :  
            The vertical orientation of the source image in the image buffer. The
            default value is usually ImageOrientation_TopDown. 
"""

However, the method actually expects a PylonImage object, as indicated by the following error message:

  Possible C/C++ prototypes are:
    Pylon::CImageFormatConverter::Convert(Pylon::IReusableImage &,Pylon::IImage const &)
    Pylon::CImageFormatConverter::Convert(Pylon::IReusableImage &,Pylon::CGrabResultPtr const &)

Attempted Solution I tried converting my bytes to a PylonImage using:

image = pylon.PylonImage()
image.AttachUserBuffer(...)

However, AttachUserBuffer failed with the same error regardless of the arguments provided:

    return _pylon.PylonImage_AttachUserBuffer(self, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Wrong number or type of arguments for overloaded function 'PylonImage_AttachUserBuffer'.
  Possible C/C++ prototypes are:
    Pylon::CPylonImage::AttachUserBuffer(void *,size_t,Pylon::EPixelType,uint32_t,uint32_t,size_t,Pylon::EImageOrientation,CPylonImageUserBufferEventHandler *)
    Pylon::CPylonImage::AttachUserBuffer(void *,size_t,Pylon::EPixelType,uint32_t,uint32_t,size_t,Pylon::EImageOrientation)
    Pylon::CPylonImage::AttachUserBuffer(void *,size_t,Pylon::EPixelType,uint32_t,uint32_t,size_t)

Question Is it possible to use Pylon's conversion on a raw buffer instead of a grabResult? If so, how can this be achieved?