diff --git a/log.h b/log.h index a2e594b..73b0f7e 100644 --- a/log.h +++ b/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 #include +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 Log &operator<<(const T &msg) { @@ -93,3 +62,5 @@ public: return *this; } }; + +} diff --git a/uvoscam.cpp b/uvoscam.cpp index 079af93..ba3947c 100644 --- a/uvoscam.cpp +++ b/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(height_), static_cast(width_), CV_8U, const_cast(data), bufferSize/width_); - cv::Mat cvResult; + const cv::Mat cvBuffer(static_cast(height_), static_cast(width_), CV_8UC1, const_cast(data)); + cv::Mat cvResult(static_cast(height_), static_cast(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(height_), static_cast(width_), CV_8UC1, const_cast(data)); + cv::Mat cvResult(static_cast(height_), static_cast(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(y); + uint8_t* colL = cvResult.ptr(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(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; } } diff --git a/uvoscam.h b/uvoscam.h index 15f244f..b94bd99 100644 --- a/uvoscam.h +++ b/uvoscam.h @@ -144,7 +144,8 @@ private: 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 pack16(ArvBuffer *buffer);