Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LinzerLee committed Sep 27, 2017
0 parents commit 4e30b10
Show file tree
Hide file tree
Showing 42 changed files with 3,829 additions and 0 deletions.
142 changes: 142 additions & 0 deletions ColorCode.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
[Project]
FileName=ColorCode.dev
Name=ColorCode
Type=1
Ver=2
ObjFiles=
Includes=C:\Users\Linzer\Documents\Projects\ColorCode\tools
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-Wall -std=c++11_@@_
Linker=lib/tools.a_@@_
IsCpp=1
Icon=
ExeOutput=UIContainer\bin
ObjectOutput=obj
LogOutput=
LogOutputEnabled=0
OverrideOutput=0
OverrideOutputName=ColorCode.exe
HostApplication=
UseCustomMakefile=0
CustomMakefile=
CommandLine=-INPUT C:\Users\Linzer\Documents\Projects\ColorCode\UIContainer\input
Folders=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0000000000000000001000000
UnitCount=6

[VersionInfo]
Major=1
Minor=0
Release=0
Build=0
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=1.0.0.0
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=1.0.0.0
AutoIncBuildNr=0
SyncProduct=1

[Unit1]
FileName=bitmap.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit2]
FileName=Main.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit3]
FileName=colorcode.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit4]
FileName=basetype.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit5]
FileName=bitmap.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit14]
FileName=tools\log\Layout.h
CompileCpp=1
Folder=tools/log
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit15]
FileName=tools\log\Logger.cpp
CompileCpp=1
Folder=tools/log
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit16]
FileName=tools\log\Logger.h
CompileCpp=1
Folder=tools/log
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

[Unit6]
FileName=colorcode.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

23 changes: 23 additions & 0 deletions ColorCode.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Editors]
Order=1,2,4,5
Focused=4
[Editor_1]
CursorCol=24
CursorRow=161
TopLine=1
LeftChar=1
[Editor_2]
CursorCol=1
CursorRow=955
TopLine=947
LeftChar=1
[Editor_4]
CursorCol=24
CursorRow=51
TopLine=1
LeftChar=1
[Editor_5]
CursorCol=28
CursorRow=82
TopLine=73
LeftChar=1
23 changes: 23 additions & 0 deletions ColorCode_private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT ! */

#ifndef COLORCODE_PRIVATE_H
#define COLORCODE_PRIVATE_H

/* VERSION DEFINITIONS */
#define VER_STRING "1.0.0.0"
#define VER_MAJOR 1
#define VER_MINOR 0
#define VER_RELEASE 0
#define VER_BUILD 0
#define COMPANY_NAME ""
#define FILE_VERSION "1.0.0.0"
#define FILE_DESCRIPTION "Developed using the Dev-C++ IDE"
#define INTERNAL_NAME ""
#define LEGAL_COPYRIGHT ""
#define LEGAL_TRADEMARKS ""
#define ORIGINAL_FILENAME ""
#define PRODUCT_NAME ""
#define PRODUCT_VERSION "1.0.0.0"

#endif /*COLORCODE_PRIVATE_H*/
5 changes: 5 additions & 0 deletions ColorCode_private.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT! */


A ICON "ColorCode.ico"
Binary file added ColorCode_private.res
Binary file not shown.
174 changes: 174 additions & 0 deletions Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#include <map>

#ifdef _WIN32
#include "dirent.h"
#else
#include <direct.h>
#include <unistd.h>
#endif

#include "tools/Define.hpp"
#include "tools/Utility.h"
#include "tools/config/Parser.h"

#include "error.h"
#include "basetype.h"
#include "bitmap.h"
#include "colorcode.h"

using namespace std;
using namespace tools::config;

int usage()
{
printf("usage: ColorCode [Options] [Params]\n");
printf("Options:\n");
printf("-H --help Print this message and exit\n");
printf("Params:\n");
printf("-INPUT --doc set directory Recognition *.BMP files from directory\n");
printf("-CFG --config file Config file path\n");
printf("-LOG --log file Log file path\n");

return (EXIT_FAILURE);
}
/********************************************************************
* Main
********************************************************************/
string GetColorCode(CONST CHAR *strFile) {
Bitmap bitmap;
UINT uiErrCode = ERROR_SUCCESS;
ColorCodeBuffer ccb;
uiErrCode = LoadBitmapFromFile(strFile, &bitmap);
InitColorCodeBuffer(&bitmap, &ccb);
ReleaseBitmap(&bitmap);

uiErrCode = ERROR_SUCCESS!=uiErrCode ? uiErrCode : EnqueueProcessStepQueue(PT_SIMILARITY);
uiErrCode = ERROR_SUCCESS!=uiErrCode ? uiErrCode : EnqueueProcessStepQueue(PT_SCAN_BORDER);
uiErrCode = ERROR_SUCCESS!=uiErrCode ? uiErrCode : EnqueueProcessStepQueue(PT_STRENGTHEN_PARTITION);
uiErrCode = ERROR_SUCCESS!=uiErrCode ? uiErrCode : EnqueueProcessStepQueue(PT_RECOGNITION_COLORCODE);

uiErrCode = ERROR_SUCCESS!=uiErrCode ? uiErrCode : ProcessData(&ccb);
// PrintReserved(&ccb);
// ConvertCCB2Bitmap(&ccb, &bitmap);
// SaveBitmapToFile("bak.bmp", &bitmap);
// ReleaseBitmap(&bitmap);
string code;

if(ERROR_SUCCESS==uiErrCode) {

for(UINT i=0; i<ccb.bRowSize; ++i) {
for(UINT j=0; j<ccb.bColSize; ++j) {
code += ColorCodeToString(ccb.abCodePoint[i][j]-1);
}
}
}
uiErrCode = ERROR_SUCCESS==uiErrCode ? uiErrCode : ReleaseColorCodeBuffer(&ccb);

return code;
}

string ParseColorCode(CONST CHAR *code) {
Parser parser;
if(parser.loadConfig("./db/data.db")) {
parser.handle();
vector<string> result = parser.config(code);
if(result.size()>0) {
return parser.config(code)[0];
}
}

return "";
}

INT main(INT argc, CHAR *argv[])
{
map<string, vector<string> > command_params = Parser::CommandParams(argc, argv);
// H选项检测
if (command_params.count("H") > 0)
{
usage();
printf("Exit Code : %d.", EXIT_SUCCESS);
return EXIT_SUCCESS;
}

if (argc<2) {
return usage();
}

// Utility组件加载器
printf("Lodding Utility component...\n");
if (!loader(command_params))
{
printf("Lode Utility component incomplete.\n");
printf("Error Code : %d\n", EXIT_FAILURE);
return EXIT_FAILURE;
}

Log("[ColorCode]");
Log("Lode Utility component complete.");
StartTimer();

// S选项检测--相似度阈值
if (command_params.count("S") > 0)
{
char* error_point = NULL;
SetSimilarityThreshold(strtod(command_params["S"][0].c_str(), &error_point));
}

DIR* pdir = NULL;
dirent* ptr = NULL;
char path[512];
string output_file, input_dir;

if (command_params["INPUT"].size() == 1)
{
input_dir = command_params["INPUT"][0];
auto pos = input_dir.size() - 1;

if ('\\' == input_dir[pos] || '/' == input_dir[pos])
input_dir.erase(pos, 1);
}

// 打开INPUT目录
if (!(pdir = opendir(input_dir.c_str())))
{
Log("打开目录失败 : %s", input_dir.c_str());
Log("Exit Code : %d.", EXIT_FAILURE);
return EXIT_FAILURE;
}

// 循环取出待识别的图片
while ((ptr = readdir(pdir)) != 0)
{
if('.'==ptr->d_name[0]) {
continue;
}
sprintf(path, "%s/%s", input_dir.c_str(), ptr->d_name);
string code = GetColorCode(path);
string info = ParseColorCode(code.c_str());
if(""!=info) {
Log("%s recognition result : [%s] %s", ptr->d_name, code.c_str(), info.c_str());
info = "start " + info;
system(info.c_str());
} else {
Log("Sorry, %s can't recognition[%s].", ptr->d_name, code.c_str());
}
}

closedir(pdir);

return 0;
}
Loading

0 comments on commit 4e30b10

Please sign in to comment.