FLIR One Developer / Blog / Topics / frames per second, overwrite data, RenderedImage / RenderedImage Object being overwritten

RenderedImage Object being overwritten

Home Forums FLIR ONE SDK Development Android development RenderedImage Object being overwritten

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

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

  • Author

    Posts

  • #7605

    Profile photo of Amit
    Amit

    Participant

    Consider following psuedo code of onFrameProcessed callback:

    
    public void onFrameProcessed(final RenderedImage renderedImage) {
    if (renderedImage is ThermoKelvinImage){
       create a new thread and run following code (part a & b) on it. 
       a) call renderedImage.thermalPixelValues() & write data to a file
       b) save frame by using renderedImage.getFrame().save(filename) method
    }
    }
    

    Usually, a flir gen2 android device processes around 5-7 frames per second.
    Now, the above code takes some time to execute. Assuming that only part a is finished so far and another onFrameProcessed callback is called(with a different renderedImage object obviously). Now, when part b is executed, it will save the new renderedImage object and not the one used in part a and that is not correct behavior.

    Is there a way to rectify this?

    #7608

    Profile photo of Allison
    Allison

    Moderator

    Hi Amit,

    As far as I can tell this is a scoping issue between threads and callback methods. To resolve this I would recommend either declaring a variable at the beginning of the thread with the value of RenderedImage, something along the lines of:

    new Thread(new Runnable() {
                    public void run() {
                        RenderedImage image = renderedImage;

    Then using this variable rather than the renderedImage variable that’s passed into onProcessed().

    Or in your thread when you call renderedImage.thermalPixelValues() in part a. You could also declare a frame variable to be used when saving the image later:

    int[] pixelsValues = image.thermalPixelValues();
    Frame frameToSave = renderedImage.getFrame();

    Then when saving you would only call:
    frameToSave.save(file where you're saving it, frameProcessor);

    Please let me know if this doesn’t work for you or there are further issues.

    Thank you,
    Allison Torchia

    #7611

    Profile photo of Amit
    Amit

    Participant

    Hi Allison,
    Thanks for replying.
    I thought object assignment in Java just copies the reference e.g. RenderedImage imageCopy = renderedImage, in this statement, only the reference to renderedImage is copied in imageCopy. So, when renderedImage change(in next callback), shouldn’t imageCopy point to the new renderedImage?

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

You must be logged in to reply to this topic.