cv::circle(inOutImg, cv::Point(rect.x + 3 * gapW, rect.y + 3 * gapH), gapW, color, -1);
}
-static int __draw_logo(cv::Mat &image, Common::EngineConfig *engineCfg)
+static int __draw_logo(cv::Mat &image, const BarcodeConfig &config)
{
- std::string logoPath;
- int error = engineCfg->getStringAttribute(std::string(MV_BARCODE_GENERATE_ATTR_EMBED_IMG_PATH), &logoPath);
- if (error != BARCODE_ERROR_NONE) {
- LOGE("getStringAttribute failed error : %d", error);
- return error;
- }
- std::string backgroundColor;
- error = engineCfg->getStringAttribute(std::string(MV_BARCODE_GENERATE_ATTR_COLOR_BACK), &backgroundColor);
- if (error != BARCODE_ERROR_NONE) {
- LOGE("getStringAttribute failed error : %d", error);
- return error;
- }
- int finderShape;
- error = engineCfg->getIntegerAttribute(std::string(MV_BARCODE_GENERATE_ATTR_FINDER_SHAPE), &finderShape);
- if (error != BARCODE_ERROR_NONE) {
- LOGE("getIntegerAttribute failed error : %d", error);
- return error;
- }
+ auto logo = cv::imread(config.logo_path.c_str(), cv::IMREAD_COLOR);
- if (!logoPath.empty()) {
- auto logo = cv::imread(logoPath.c_str(), cv::IMREAD_COLOR);
-
- int color_decimal = strtol(backgroundColor.c_str(), nullptr, 16);
- int B = color_decimal % 256;
- color_decimal /= 256;
- int G = color_decimal % 256;
- color_decimal /= 256;
- int R = color_decimal;
-
- auto color_frame = cv::Scalar(B, G, R);
- auto color_black = cv::Scalar(255, 255, 255);
-
- auto logoSize = image.size() / 5;
- auto logoFrameSize = logoSize + logoSize / 10;
-
- cv::resize(logo, logo, logoSize);
- cv::Mat maskMat = cv::Mat::zeros(image.size(), image.type());
- cv::Mat logoMat = cv::Mat::zeros(image.size(), image.type());
- auto logoRect = cv::Rect((image.size() - logoSize) / 2, logoSize);
- auto logoFrameRect = cv::Rect((image.size() - logoFrameSize) / 2, logoFrameSize);
- logo.copyTo(logoMat(logoRect));
-
- switch (finderShape) {
- case MV_BARCODE_GENERATE_ATTR_SHAPE_ROUND_RECT:
- __round_rect(maskMat, logoRect, color_black);
- __round_rect(image, logoFrameRect, color_frame);
- break;
- case MV_BARCODE_GENERATE_ATTR_SHAPE_CIRCLE:
- cv::circle(maskMat, image.size() / 2, logoSize.width / 2, color_black, -1);
- cv::circle(image, image.size() / 2, logoFrameSize.width / 2, color_frame, -1);
- break;
-
- default:
- cv::rectangle(maskMat, logoRect, color_black, -1);
- cv::rectangle(image, logoFrameRect, color_frame, -1);
- break;
- }
- cv::multiply(cv::Scalar::all(1.0) - maskMat, image, image);
- cv::multiply(maskMat / 255, logoMat, logoMat);
- cv::add(logoMat, image, image);
+ int color_decimal = strtol(config.bgcolor.c_str(), nullptr, 16);
+ int R = color_decimal % 256;
+ color_decimal /= 256;
+ int G = color_decimal % 256;
+ color_decimal /= 256;
+ int B = color_decimal;
+
+ auto color_frame = cv::Scalar(B, G, R);
+ auto color_white = cv::Scalar(255, 255, 255);
+
+ auto logoSize = image.size() / 5;
+ auto logoFrameSize = logoSize + logoSize / 10;
+
+ cv::resize(logo, logo, logoSize);
+ cv::Mat maskMat = cv::Mat::zeros(image.size(), image.type());
+ cv::Mat logoMat = cv::Mat::zeros(image.size(), image.type());
+ auto logoRect = cv::Rect((image.size() - logoSize) / 2, logoSize);
+ auto logoFrameRect = cv::Rect((image.size() - logoFrameSize) / 2, logoFrameSize);
+ logo.copyTo(logoMat(logoRect));
+
+ switch (config.finder_shape) {
+ case MV_BARCODE_GENERATE_ATTR_SHAPE_ROUND_RECT:
+ __round_rect(maskMat, logoRect, color_white);
+ __round_rect(image, logoFrameRect, color_frame);
+ break;
+ case MV_BARCODE_GENERATE_ATTR_SHAPE_CIRCLE:
+ cv::circle(maskMat, image.size() / 2, logoSize.width / 2, color_white, -1);
+ cv::circle(image, image.size() / 2, logoFrameSize.width / 2, color_frame, -1);
+ break;
+
+ default:
+ cv::rectangle(maskMat, logoRect, color_white, -1);
+ cv::rectangle(image, logoFrameRect, color_frame, -1);
+ break;
}
- return error;
+ cv::multiply(cv::Scalar::all(1.0) - maskMat, image, image);
+ cv::multiply(maskMat / 255, logoMat, logoMat);
+ cv::add(logoMat, image, image);
+
+ return MEDIA_VISION_ERROR_NONE;
}
-int write_buffer_to_img(zint_symbol *symbol, const std::string &imageFileName, mv_barcode_image_format_e image_format,
- const int imageWidth, const int imageHeight, mv_engine_config_h engine_cfg)
+int write_buffer_to_img(zint_symbol *symbol, const BarcodeConfig &config)
{
+ std::string imageFileName = config.image_path;
/* find directory */
std::string prefix_imageFileName = imageFileName.substr(0, imageFileName.find_last_of('/'));
LOGD("prefix_path: %s", prefix_imageFileName.c_str());
/* check current extension */
std::vector<std::string> expectedExtensions;
std::vector<int> compressionParams;
- auto imageFormat = convertImageFormat(image_format);
+ auto imageFormat = convertImageFormat(config.image_format);
int error = getFormatEncodingInfo(imageFormat, expectedExtensions, compressionParams);
if (BARCODE_ERROR_NONE != error || expectedExtensions.empty()) {
resultFilePath += expectedExtensions[0];
cv::Mat image(symbol->bitmap_height, symbol->bitmap_width, CV_8UC3, symbol->bitmap);
- cv::resize(image, image, cv::Size(imageWidth, imageHeight), 0, 0, cv::INTER_AREA);
+ cv::resize(image, image, cv::Size(config.image_width, config.image_height), 0, 0, cv::INTER_AREA);
- auto engineCfg = static_cast<Common::EngineConfig *>(engine_cfg);
- if (engineCfg) {
- error = __draw_logo(image, engineCfg);
+ if (!config.logo_path.empty()) {
+ error = __draw_logo(image, config);
if (error != MEDIA_VISION_ERROR_NONE) {
LOGE("__draw_logo error code : %d", error);
return error;
if (!engine_cfg)
return MEDIA_VISION_ERROR_NONE;
+ auto engineCfg = static_cast<Common::EngineConfig *>(engine_cfg);
+
int value;
int error = mv_engine_config_get_int_attribute(engine_cfg, MV_BARCODE_GENERATE_ATTR_TEXT, &value);
if (error != MEDIA_VISION_ERROR_NONE) {
free(fgcolor);
free(bgcolor);
+ error = engineCfg->getStringAttribute(std::string(MV_BARCODE_GENERATE_ATTR_EMBED_IMG_PATH), &logo_path);
+ if (error != BARCODE_ERROR_NONE) {
+ LOGE("getStringAttribute failed error : %d", error);
+ return error;
+ }
+
return MEDIA_VISION_ERROR_NONE;
}