/** * uvoscam * Copyright (C) 2021 Carl Klemm * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 3 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #pragma once #include #include #include #include #include #include #include typedef struct _ArvStream ArvStream; typedef struct _ArvBuffer ArvBuffer; typedef struct _ArvCamera ArvCamera; namespace cam { class Camera { public: struct Description { std::string vendor; std::string serial; std::string id; std::string model; }; static constexpr size_t BUFFER_DEPTH = 8; typedef int TriggerMode; static constexpr TriggerMode TRIGGER_FREE = 0; static constexpr TriggerMode TRIGGER_SOFTWARE = 1; static constexpr TriggerMode TRIGGER_HARDWARE = 2; typedef int BayerMode; static constexpr BayerMode BAYER_RED = 0; static constexpr BayerMode BAYER_GREEN = 1; static constexpr BayerMode BAYER_BLUE = 2; static constexpr BayerMode BAYER_PASSTHOUGH = 3; static constexpr BayerMode BAYER_DEBAYER = 4; typedef int AquisitionMode; static constexpr AquisitionMode MODE_FREE = 0; static constexpr AquisitionMode MODE_SINGLE = 1; private: ArvStream* aStream_ = nullptr; ArvCamera* aCamera_ = nullptr; unsigned int width_; unsigned int height_; int64_t format = -1; inline static bool scanned_ = false; ArvBuffer* imageBuffers[BUFFER_DEPTH] = {0}; BayerMode bayerMode = BAYER_DEBAYER; ArvBuffer* decodeBuffer = nullptr; std::mutex decodeBufferMutex; std::condition_variable bufferCondition; std::mutex bufferConditionMutex; std::thread* decoderThread = nullptr; std::atomic_bool join; std::atomic_bool run; AquisitionMode aqmode = MODE_FREE; void decoderThreadFunc(); std::function callback_; bool setupCamera(); bool chooseFormat(); cv::Mat debayer(ArvBuffer *buffer); cv::Mat pack8(ArvBuffer *buffer, bool color); cv::Mat pack16(ArvBuffer *buffer); public: static std::vector getAvailableCameras(bool update = false); Camera(std::function callback); bool openCamera(const std::string& name); bool openCamera(const Camera::Description& camera); bool openCamera(const size_t index); ~Camera(); bool isOpen(); bool setAcquisitionMode(AquisitionMode mode); bool setExposureTime(uint64_t us); uint64_t getExposureTime(); double getFrameRate(); bool setFrameRate(double rate); int64_t getPixelFormat(); bool setExposureAuto(bool enable); bool startAcquisition(); bool stopAcquisition(); void getSize(unsigned int* x, unsigned int* y); void setBayerMode(Camera::BayerMode mode); Camera::BayerMode getBayerMode(); void setTriggerMode(Camera::TriggerMode mode); void trigger(); Camera::Description getDescription(); static void aCallback(void* instance, int type, ArvBuffer *buffer); }; }