How to use the pypylon.pylon.OutputBitAlignment_MsbAligned function in pypylon

To help you get started, we’ve selected a few pypylon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github soham96 / trash_classifier / trash_classifier.py View on Github external
x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)

    return np.asarray(x)

prediction_list=['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
model=load_model('models/model1.h5', custom_objects={'relu6': mobilenet.relu6})

camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())

numberOfImagesToGrab = 100
camera.StartGrabbingMax(numberOfImagesToGrab)

converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
i=0
while camera.IsGrabbing():
    time.sleep(0.005)
    grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)

    if grabResult.GrabSucceeded():
        # Access the image data.
        print("SizeX: ", grabResult.Width)
        print("SizeY: ", grabResult.Height)
        #import ipdb; ipdb.set_trace()
        img = converter.Convert(grabResult).GetArray()
        cv2.imwrite('pic.png', img)
        pred_img=pp_image(img)
        yo=model.predict(pred_img)
        pred=prediction_list[np.argmax(yo)]
        cv2.putText(img, pred, (10,1000), cv2.FONT_HERSHEY_SIMPLEX, 5, (0,0,0), 5, False)
github mbalatsko / pypylon-opencv-viewer / pypylon_opencv_viewer / viewer.py View on Github external
def _run_continuous_shot(self, grab_strategy=pylon.GrabStrategy_LatestImageOnly,
                                        window_size=None, image_folder='.'):
        self._camera.StopGrabbing()

        # converting to opencv bgr format
        converter = pylon.ImageFormatConverter()
        converter.OutputPixelFormat = pylon.PixelType_BGR8packed
        converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned

        if(not self._impro_own_window):
            cv2.namedWindow('camera_image', cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL)
            if(window_size is not None):
                cv2.resizeWindow('camera_image', window_size[0], window_size[1])

        self._camera.StartGrabbing(grab_strategy)
        try:
            while(self._camera.IsGrabbing()):
                grab_result = self._camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)

                if grab_result.GrabSucceeded():
                    # Access the image data
                    image = converter.Convert(grab_result)
                    img = image.GetArray()
github mbalatsko / pypylon-opencv-viewer / pypylon_opencv_viewer / viewer.py View on Github external
Parameters
        ----------
        filename : str
            Filename of grabbed image

        Returns
        -------
        None
        """
        if self._camera is None or not self._camera.IsOpen():
            raise ValueError("Camera object {} is closed.".format(self._camera))

        converter = pylon.ImageFormatConverter()
        converter.OutputPixelFormat = pylon.PixelType_BGR8packed
        converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned

        grab_result = self._camera.GrabOne(5000)
        image = converter.Convert(grab_result)
        img = image.GetArray()
        if self._impro_function:
            img = self._impro_function(img)
        cv2.imwrite(filename, img)
github basler / pypylon / samples / utilityimageformatconverter1.py View on Github external
camera.Close()
        return result
    except genicam.GenericException as e:
        print("Could not grab an image: ", e.GetDescription())


try:
    # The image format converter basics.
    # First the image format converter class must be created.
    converter = pylon.ImageFormatConverter()

    # Second the converter must be parameterized.
    converter.OutputPixelFormat = pylon.PixelType_Mono16
    converter.OutputBitAlignment = "MsbAligned"
    # or alternatively
    converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned


    # Then it can be used to convert input images to
    # the target image format.

    # Grab an image
    image = grab_image()
    show_image(image, "Source Image")

    # Now we can check if conversion is required.
    if (converter.ImageHasDestinationFormat(image)):
        show_image(image, "No conversion needed.")
    else:
        # Convert the image. Note that there are more overloaded Convert methods avilable, e.g.
        # for converting the image from or to a user buffer.
        target_image = converter.Convert(image)