FLIR One Developer / Blog / Topics / FLIR One, Palette / Code sometimes generates initial gray bitmap

Code sometimes generates initial gray bitmap

Home Forums FLIR developer community General discussion Code sometimes generates initial gray bitmap

Tagged: ,

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Allison Allison 1 year, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)

  • Author

    Posts

  • #7548

    Profile photo of Charles
    Charles

    Participant

    I am basically following FLIR’s example to get the image stream. However, one out of five times I get only gray images when I start the app. I can correct the problem by manually changing the palette in my app. So I suspect that somewhere the initial palette setting is ignored when the device starts the stream.

    Here are the basic steps in my code:

    1) Creating a frame processor:

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            frameProcessor = new FrameProcessor(this, this, EnumSet.of(RenderedImage.ImageType.BlendedMSXRGBA8888Image, RenderedImage.ImageType.ThermalRadiometricKelvinImage));
            frameProcessor.setVividIrEnabled(true);
    
        }
    

    2) Setting the palette while starting the app:

        protected void onStart() {
            super.onStart();
            try {
                Device.startDiscovery(this, this);
            } catch (IllegalStateException e) {
                // it's okay if we've already started discovery
            } catch (SecurityException e) {
                // On some platforms, we need the user to select the app to give us permisison to the USB device.
                Toast.makeText(this, "Insert thermal camera and select " + getString(R.string.app_name), Toast.LENGTH_LONG).show();
                // There is likely a cleaner way to recover, but for now, exit the activity and wait for user to follow the instructions;
                finish();
            }
            restoreState();
            frameProcessor.setImagePalette(RenderedImage.Palette.valueOf(selectedPalette));
        }
    

    3) Receiving frame:

        public void onFrameReceived(Frame frame) {
            frameProcessor.processFrame(frame, FrameProcessor.QueuingOption.CLEAR_QUEUED);
        }
    

    4) Processing frame:

        public void onFrameProcessed(final RenderedImage renderedImage) {
                        if (thermalBitmap == null) {
                            thermalBitmap = renderedImage.getBitmap();
                        } else {
                            try {
                                renderedImage.copyToBitmap(thermalBitmap);
                            } catch (IllegalArgumentException e) {
                                thermalBitmap = renderedImage.getBitmap();
                            }
                        }
                        updateThermalImageView(thermalBitmap);
         }
    

    What in the above steps might go wrong in terms of reliably getting a colored image stream (instead of occasionally getting a gray image stream)?

    #7549

    Profile photo of Allison
    Allison

    Moderator

    Hi Charles,

    I would guess it has to do with where you initialize selectedPalette. In onCreate or wherever you initialize it are you explicitly setting its value or are you waiting for some other event to trigger that?

    Thank you,
    Allison Torchia

    #7551

    Profile photo of Charles
    Charles

    Participant

    Thanks for your reply (as always). When I printed out the palette in the onFrameProcessed method, it did say the right palette was set, despite the fact that the image was still gray. Even after I tried to force the palette by setting every time onFrameProcessed is called, there was still a chance that I would get only gray images (but less, I think, compared with the case of not doing this).

    #7563

    Profile photo of Allison
    Allison

    Moderator

    Hi Charles,

    I’m still looking into this and I’ll update you when I have more information. I didn’t want to leave you without any reply too long.

    Thank you,
    Allison Torchia

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.