add support for bayergb
This commit is contained in:
parent
7af2622012
commit
7809c75539
53
log.h
53
log.h
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Cam
|
||||
* Lubricant Detecter
|
||||
* Copyright (C) 2021 Carl Klemm
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@ -21,6 +21,9 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace cam
|
||||
{
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
@ -37,51 +40,17 @@ private:
|
||||
bool opened = false;
|
||||
Level msglevel = DEBUG;
|
||||
|
||||
inline 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;
|
||||
}
|
||||
std::string getLabel(Level level);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
inline static bool headers = false;
|
||||
inline static Level level = WARN;
|
||||
static bool headers;
|
||||
static Level level;
|
||||
static bool endline;
|
||||
|
||||
Log() {}
|
||||
Log(Level type)
|
||||
{
|
||||
msglevel = type;
|
||||
if(headers)
|
||||
{
|
||||
operator << ("["+getLabel(type)+"]");
|
||||
}
|
||||
}
|
||||
|
||||
~Log()
|
||||
{
|
||||
if(opened)
|
||||
{
|
||||
std::cout<<'\n';
|
||||
}
|
||||
opened = false;
|
||||
}
|
||||
Log(Level type);
|
||||
~Log();
|
||||
|
||||
template<class T> Log &operator<<(const T &msg)
|
||||
{
|
||||
@ -93,3 +62,5 @@ public:
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
68
uvoscam.cpp
68
uvoscam.cpp
@ -31,12 +31,12 @@
|
||||
|
||||
using namespace cam;
|
||||
|
||||
cv::Mat Camera::debayer(ArvBuffer *buffer)
|
||||
cv::Mat Camera::debayerBG(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_8U, const_cast<void*>(data), bufferSize/width_);
|
||||
cv::Mat cvResult;
|
||||
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_BayerBG2BGR);
|
||||
@ -77,6 +77,52 @@ cv::Mat Camera::debayer(ArvBuffer *buffer)
|
||||
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)
|
||||
{
|
||||
size_t bufferSize;
|
||||
@ -114,7 +160,14 @@ void Camera::decoderThreadFunc()
|
||||
if(format == ARV_PIXEL_FORMAT_BAYER_BG_8)
|
||||
{
|
||||
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
|
||||
callback_(pack8(decodeBuffer, false));
|
||||
}
|
||||
@ -168,18 +221,15 @@ bool Camera::chooseFormat()
|
||||
gint64* formats = arv_camera_dup_available_pixel_formats(aCamera_, &count, &error);
|
||||
if(error)
|
||||
return false;
|
||||
for(guint i = 0; i < count && format < 0; ++i)
|
||||
for(guint i = 0; i < count; ++i)
|
||||
{
|
||||
switch(formats[i])
|
||||
{
|
||||
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_BAYER_BG_8:
|
||||
case ARV_PIXEL_FORMAT_BAYER_GB_8:
|
||||
format = formats[i];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user