Inital commit

This commit is contained in:
2021-06-04 21:05:04 +02:00
commit 89cd91d935
5 changed files with 850 additions and 0 deletions

129
uvoscam.h Normal file
View File

@ -0,0 +1,129 @@
/**
* 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 <string>
#include <functional>
#include <condition_variable>
#include <stdint.h>
#include <thread>
#include <atomic>
#include <opencv2/core/mat.hpp>
#include <arv.h>
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;
ArvInterface interface;
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;
static void aCallback(void* instance, ArvStreamCallbackType type, ArvBuffer *buffer);
void decoderThreadFunc();
std::function<void(cv::Mat)> 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<Camera::Description> getAvailableCameras(bool update = false);
Camera(std::function<void(cv::Mat)> 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();
};
}