相机一次扫四个二维码,后续跟进吧

记录日志
G_HelperMain.h


#pragma once
#include "include/glog/logging.h"

#ifdef DEBUG
#pragma comment(lib,"lib/glogd.lib")
#else
#pragma comment(lib,"lib/glog.lib")
#endif // DEBUG



class GlogHelper
{
public:
	GlogHelper(const char* name);
	~GlogHelper();
	void CreateFolder(char* fileName);
	void Info(int id, std::string);
	void Error(int id, std::string);
	
};


G_HelperMain.cpp

#include <iostream>
#include "G_HelperMain.h"
#include <io.h>
#include <direct.h>

GlogHelper::GlogHelper(const char* name)
{
	// 初始化应用进程名
	google::InitGoogleLogging(name);
	// 设置错误级别大于等于多少时输出到文件
	// 参数2为日志存放目录和日志文件前缀
	char a[] = "log";
	CreateFolder(a);
	google::SetLogDestination(google::GLOG_INFO, ".//log//InfoCollect_");
	google::SetLogDestination(google::GLOG_ERROR, ".//log/ErrorCollect_");
	google::SetStderrLogging(google::GLOG_INFO);
	google::SetLogFilenameExtension(".log");

	FLAGS_colorlogtostderr = true;  //set log color
	// 是否将日志输出到标准错误是不是日志文件
	FLAGS_logtostderr = false;
	// 是否同时将日志发送到标准错误和日志文件中
	FLAGS_alsologtostderr = true;
	// 当日志级别大于此级别时,自动将此日志输出到标准错误中
	FLAGS_stderrthreshold = google::FATAL;
	// 当日志级别大于此级别时会马上输出,而不缓存
	FLAGS_logbuflevel = google::WARNING;
	// 缓存最久长时间为多久
	FLAGS_logbufsecs = 0;
	// 当日志文件达到多少时,进行转存,以M为单位
	FLAGS_max_log_size = 10;
	// 当磁盘已满时,停止输出日志文件
	FLAGS_stop_logging_if_full_disk = true;
}

GlogHelper::~GlogHelper()
{
	google::ShutdownGoogleLogging();
}

void GlogHelper::CreateFolder(char* fileName)
{
	//文件夹名称
	char* folderName = fileName;

	// 文件夹不存在则创建文件夹
	if (_access(folderName, 0) == -1)
	{
		_mkdir(folderName);
	}
}

void GlogHelper::Info(int id, std::string msg)
{
#if 1
	LOG(INFO) << std::to_string(id) + ":" + msg;
#endif // 1

}

void GlogHelper::Error(int id, std::string msg)
{
#if 1
	LOG(ERROR) << std::to_string(id) + ":" + msg;
#endif // 1
}




zbar扫码

#pragma once
#include <zbar.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>      
#include "G_HelperMain.h"
#include <thread>


using namespace std;
using namespace zbar;
using namespace cv;


zbar_image_scanner_t *scanner[4] = { NULL };
zbar_image_t *image[4] = { NULL };
//glog初始配置
GlogHelper Collect("Collect");

const int barCount = 4;


void test(const int& aIndex) {
	Collect.Info(aIndex, "识别开始");
	int n = zbar_scan_image(scanner[aIndex], image[aIndex]);
	Collect.Info(aIndex, "识别结束");
	const zbar_symbol_t *symbol = zbar_image_first_symbol(image[aIndex]);
	for (; symbol; symbol = zbar_symbol_next(symbol)) {
		zbar_symbol_type_t typ = zbar_symbol_get_type(symbol);
		const char *data = zbar_symbol_get_data(symbol);
		printf("%d:decoded %s symbol \"%s\"\n",
			aIndex,zbar_get_symbol_name(typ), data);
	}
}

enum StatusDe
{
	Default=0,
	Success=1,
	Yes=1,
	Fail=-1,
	No=-1,
	Err=-2,
};


StatusDe IsReadImgFail(int index,Mat getImage) {
	if (!getImage.data) {
		cout << "请确认图片" << endl;
		Collect.Error(index, "请确认图片");
		system("pause");
		return Fail;
	}
	return Success;
}

int main(int argc, char*argv[])
{
	
	Collect.Info(0, "初始化配置开始");
	for (int aIndex = 0; aIndex < barCount; aIndex++)
	{
		scanner[aIndex] = zbar_image_scanner_create();
		zbar_image_scanner_set_config(scanner[aIndex], ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
	}

	Collect.Info(0, "初始化配置结束");

	Mat src[barCount];
	Mat imageGray[barCount];
	int width[barCount];
	int height[barCount];
	uchar *raw[barCount];

	Collect.Info(0, "读入图像开始");
	//读入图像
	src[0] = imread("./image/0.png");
	src[1] = imread("./image/1.png");
	src[2] = imread("./image/2.png");
	src[3] = imread("./image/3.png");

	for (int aIndex = 0; aIndex < barCount; aIndex++)
	{
		if (Success !=IsReadImgFail(aIndex,src[aIndex]))
		{
			Collect.Error(aIndex,"失败");
			return -1;
		}
	}
	Collect.Info(0, "读入图像结束");

	Collect.Info(0, "处理成灰度图开始");
	for (int aIndex = 0; aIndex < barCount; aIndex++)
	{
		//转成灰度图
		cvtColor(src[aIndex], imageGray[aIndex], COLOR_BGR2GRAY);
	}
	Collect.Info(0, "处理成灰度图结束");

	
	for (int aIndex = 0; aIndex < barCount; aIndex++)
	{
		width[aIndex] = imageGray[aIndex].cols;
		height[aIndex] = imageGray[aIndex].rows;
		raw[aIndex] = (uchar *)imageGray[aIndex].data;

		image[aIndex] = zbar_image_create();
		const std::string& format = "Y800";
		unsigned long fourcc = ((format[0] & 0xff) |
			((format[1] & 0xff) << 8) |
			((format[2] & 0xff) << 16) |
			((format[3] & 0xff) << 24));
		zbar_image_set_format(image[aIndex], fourcc);
		zbar_image_set_size(image[aIndex], width[aIndex], height[aIndex]);
		zbar_image_set_data(image[aIndex], raw[aIndex], width[aIndex] * height[aIndex], zbar_image_free_data);
	}

	thread t0(test, 0);
	thread t1(test, 1);
	thread t2(test, 2);
	thread t3(test, 3);

	t0.join();
	t1.join();
	t2.join();
	t3.join();

	for (int aIndex = 0; aIndex < barCount; aIndex++)
	{
		//这是释放了空指针吗?会报错
		//zbar_image_destroy(image);
		zbar_image_scanner_destroy(scanner[aIndex]);
	}
	//waitKey();
	return 0;
}

我编译好的32位的glog和zbar,连同整个工程
下载地址:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容码获取二维码内容

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值