001/*
002 * Copyright (C) Photon Vision.
003 *
004 * This program is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package org.photonvision.vision.frame;
019
020import org.photonvision.common.util.math.MathUtils;
021import org.photonvision.vision.opencv.CVMat;
022import org.photonvision.vision.opencv.Releasable;
023
024public class Frame implements Releasable {
025    public final long sequenceID;
026    public final long timestampNanos;
027
028    // Frame should at _least_ contain the thresholded frame, and sometimes the color image
029    public final CVMat colorImage;
030    public final CVMat processedImage;
031    public final FrameThresholdType type;
032
033    public final FrameStaticProperties frameStaticProperties;
034
035    public Frame(
036            long sequenceID,
037            CVMat color,
038            CVMat processed,
039            FrameThresholdType type,
040            long timestampNanos,
041            FrameStaticProperties frameStaticProperties) {
042        this.sequenceID = sequenceID;
043        this.colorImage = color;
044        this.processedImage = processed;
045        this.type = type;
046        this.timestampNanos = timestampNanos;
047        this.frameStaticProperties = frameStaticProperties;
048    }
049
050    public Frame(
051            long sequenceID,
052            CVMat color,
053            CVMat processed,
054            FrameThresholdType processType,
055            FrameStaticProperties frameStaticProperties) {
056        this(sequenceID, color, processed, processType, MathUtils.wpiNanoTime(), frameStaticProperties);
057    }
058
059    public Frame() {
060        this(
061                -1,
062                new CVMat(),
063                new CVMat(),
064                FrameThresholdType.NONE,
065                MathUtils.wpiNanoTime(),
066                new FrameStaticProperties(0, 0, 0, null));
067    }
068
069    public void copyTo(Frame destFrame) {
070        colorImage.getMat().copyTo(destFrame.colorImage.getMat());
071        processedImage.getMat().copyTo(destFrame.processedImage.getMat());
072    }
073
074    @Override
075    public void release() {
076        colorImage.release();
077        processedImage.release();
078    }
079}