add support for bayergb
This commit is contained in:
53
log.h
53
log.h
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Cam
|
* Lubricant Detecter
|
||||||
* Copyright (C) 2021 Carl Klemm
|
* Copyright (C) 2021 Carl Klemm
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@ -21,6 +21,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace cam
|
||||||
|
{
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -37,51 +40,17 @@ private:
|
|||||||
bool opened = false;
|
bool opened = false;
|
||||||
Level msglevel = DEBUG;
|
Level msglevel = DEBUG;
|
||||||
|
|
||||||
inline std::string getLabel(Level level)
|
std::string getLabel(Level level);
|
||||||
{
|
|
||||||
std::string label;
|
|
||||||
switch(level)
|
|
||||||
{
|
|
||||||
case DEBUG:
|
|
||||||
label = "DEBUG";
|
|
||||||
break;
|
|
||||||
case INFO:
|
|
||||||
label = "INFO ";
|
|
||||||
break;
|
|
||||||
case WARN:
|
|
||||||
label = "WARN ";
|
|
||||||
break;
|
|
||||||
case ERROR:
|
|
||||||
label = "ERROR";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static bool headers;
|
||||||
inline static bool headers = false;
|
static Level level;
|
||||||
inline static Level level = WARN;
|
static bool endline;
|
||||||
|
|
||||||
Log() {}
|
Log() {}
|
||||||
Log(Level type)
|
Log(Level type);
|
||||||
{
|
~Log();
|
||||||
msglevel = type;
|
|
||||||
if(headers)
|
|
||||||
{
|
|
||||||
operator << ("["+getLabel(type)+"]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~Log()
|
|
||||||
{
|
|
||||||
if(opened)
|
|
||||||
{
|
|
||||||
std::cout<<'\n';
|
|
||||||
}
|
|
||||||
opened = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T> Log &operator<<(const T &msg)
|
template<class T> Log &operator<<(const T &msg)
|
||||||
{
|
{
|
||||||
@ -93,3 +62,5 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
68
uvoscam.cpp
68
uvoscam.cpp
@ -31,12 +31,12 @@
|
|||||||
|
|
||||||
using namespace cam;
|
using namespace cam;
|
||||||
|
|
||||||
cv::Mat Camera::debayer(ArvBuffer *buffer)
|
cv::Mat Camera::debayerBG(ArvBuffer *buffer)
|
||||||
{
|
{
|
||||||
size_t bufferSize;
|
size_t bufferSize;
|
||||||
const void* data = arv_buffer_get_data(buffer, &bufferSize);
|
const void* data = arv_buffer_get_data(buffer, &bufferSize);
|
||||||
const cv::Mat cvBuffer(static_cast<int>(height_), static_cast<int>(width_), CV_8U, const_cast<void*>(data), bufferSize/width_);
|
const cv::Mat cvBuffer(static_cast<int>(height_), static_cast<int>(width_), CV_8UC1, const_cast<void*>(data));
|
||||||
cv::Mat cvResult;
|
cv::Mat cvResult(static_cast<int>(height_), static_cast<int>(width_), CV_8UC3);
|
||||||
if(bayerMode == BAYER_DEBAYER)
|
if(bayerMode == BAYER_DEBAYER)
|
||||||
{
|
{
|
||||||
cv::cvtColor(cvBuffer, cvResult, cv::COLOR_BayerBG2BGR);
|
cv::cvtColor(cvBuffer, cvResult, cv::COLOR_BayerBG2BGR);
|
||||||
@ -77,6 +77,52 @@ cv::Mat Camera::debayer(ArvBuffer *buffer)
|
|||||||
return cvResult;
|
return cvResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cv::Mat Camera::debayerGB(ArvBuffer *buffer)
|
||||||
|
{
|
||||||
|
size_t bufferSize;
|
||||||
|
const void* data = arv_buffer_get_data(buffer, &bufferSize);
|
||||||
|
const cv::Mat cvBuffer(static_cast<int>(height_), static_cast<int>(width_), CV_8UC1, const_cast<void*>(data));
|
||||||
|
cv::Mat cvResult(static_cast<int>(height_), static_cast<int>(width_), CV_8UC3);
|
||||||
|
if(bayerMode == BAYER_DEBAYER)
|
||||||
|
{
|
||||||
|
cv::cvtColor(cvBuffer, cvResult, cv::COLOR_BayerGB2BGR);
|
||||||
|
}
|
||||||
|
else if(bayerMode == BAYER_RED || bayerMode == BAYER_BLUE)
|
||||||
|
{
|
||||||
|
cvBuffer.copyTo(cvResult);
|
||||||
|
for(int y = 0; y < cvResult.rows; y+=2)
|
||||||
|
{
|
||||||
|
uint8_t* colH = cvResult.ptr<uint8_t>(y);
|
||||||
|
uint8_t* colL = cvResult.ptr<uint8_t>(y+1);
|
||||||
|
for(int x = 0; x < cvResult.cols; x+=2)
|
||||||
|
{
|
||||||
|
if(bayerMode == BAYER_BLUE)
|
||||||
|
{
|
||||||
|
colH[x] = colH[x+1];
|
||||||
|
colL[x] = colH[x+1];
|
||||||
|
colL[x+1] = colH[x+1];
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
colH[x] = colL[x];
|
||||||
|
colH[x+1] = colL[x];
|
||||||
|
colL[x+1] = colL[x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(bayerMode == BAYER_GREEN)
|
||||||
|
{
|
||||||
|
cvBuffer.copyTo(cvResult);
|
||||||
|
for(int y = 0; y < cvResult.rows; ++y)
|
||||||
|
{
|
||||||
|
uint8_t* col = cvResult.ptr<uint8_t>(y);
|
||||||
|
for(int x = 0; x < cvResult.cols; x+=2)
|
||||||
|
col[x+(y & 1)] = col[x+!(y & 1)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cvResult;
|
||||||
|
}
|
||||||
|
|
||||||
cv::Mat Camera::pack8(ArvBuffer *buffer, bool color)
|
cv::Mat Camera::pack8(ArvBuffer *buffer, bool color)
|
||||||
{
|
{
|
||||||
size_t bufferSize;
|
size_t bufferSize;
|
||||||
@ -114,7 +160,14 @@ void Camera::decoderThreadFunc()
|
|||||||
if(format == ARV_PIXEL_FORMAT_BAYER_BG_8)
|
if(format == ARV_PIXEL_FORMAT_BAYER_BG_8)
|
||||||
{
|
{
|
||||||
if(bayerMode != BAYER_PASSTHOUGH)
|
if(bayerMode != BAYER_PASSTHOUGH)
|
||||||
callback_(debayer(decodeBuffer));
|
callback_(debayerBG(decodeBuffer));
|
||||||
|
else
|
||||||
|
callback_(pack8(decodeBuffer, false));
|
||||||
|
}
|
||||||
|
else if(format == ARV_PIXEL_FORMAT_BAYER_GB_8)
|
||||||
|
{
|
||||||
|
if(bayerMode != BAYER_PASSTHOUGH)
|
||||||
|
callback_(debayerGB(decodeBuffer));
|
||||||
else
|
else
|
||||||
callback_(pack8(decodeBuffer, false));
|
callback_(pack8(decodeBuffer, false));
|
||||||
}
|
}
|
||||||
@ -168,18 +221,15 @@ bool Camera::chooseFormat()
|
|||||||
gint64* formats = arv_camera_dup_available_pixel_formats(aCamera_, &count, &error);
|
gint64* formats = arv_camera_dup_available_pixel_formats(aCamera_, &count, &error);
|
||||||
if(error)
|
if(error)
|
||||||
return false;
|
return false;
|
||||||
for(guint i = 0; i < count && format < 0; ++i)
|
for(guint i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
switch(formats[i])
|
switch(formats[i])
|
||||||
{
|
{
|
||||||
case ARV_PIXEL_FORMAT_MONO_8:
|
case ARV_PIXEL_FORMAT_MONO_8:
|
||||||
//case ARV_PIXEL_FORMAT_MONO_10:
|
|
||||||
//case ARV_PIXEL_FORMAT_MONO_12:
|
|
||||||
case ARV_PIXEL_FORMAT_RGB_8_PLANAR:
|
case ARV_PIXEL_FORMAT_RGB_8_PLANAR:
|
||||||
case ARV_PIXEL_FORMAT_BAYER_BG_8:
|
case ARV_PIXEL_FORMAT_BAYER_BG_8:
|
||||||
|
case ARV_PIXEL_FORMAT_BAYER_GB_8:
|
||||||
format = formats[i];
|
format = formats[i];
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,8 @@ private:
|
|||||||
|
|
||||||
bool chooseFormat();
|
bool chooseFormat();
|
||||||
|
|
||||||
cv::Mat debayer(ArvBuffer *buffer);
|
cv::Mat debayerBG(ArvBuffer *buffer);
|
||||||
|
cv::Mat debayerGB(ArvBuffer *buffer);
|
||||||
cv::Mat pack8(ArvBuffer *buffer, bool color);
|
cv::Mat pack8(ArvBuffer *buffer, bool color);
|
||||||
cv::Mat pack16(ArvBuffer *buffer);
|
cv::Mat pack16(ArvBuffer *buffer);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user