完善目录结构

完善了目录结构,添加了以前的web段com组件调用的代码(在/测试目录下)(部署没有使用到)
This commit is contained in:
yanshui177
2017-05-17 20:43:16 +08:00
parent ad754709a5
commit 6dcd378738
1246 changed files with 671388 additions and 517 deletions

View File

@@ -0,0 +1,50 @@
/* 程序名Cjbsb.c
功能:读入图像文件,甄别图像的角标
*/
#include <cv.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>
extern IplImage* src;
IplImage* Cjbsb(IplImage* img, IplImage* imgjbsb, int jbwhite, int jbblack)
{
/*定义变量*/
int i, j, jbi = 0, jbj = 0;
int height, width, step, channels;
uchar *data;
int brklab = 0;
/* 获取图像信息*/
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
// IplImage* imgjbsb = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvCopy(img, imgjbsb, NULL);
uchar *imgjbsbdata = (uchar *)imgjbsb->imageData;
//以角标为起点进行裁剪与画框
CvSize jbcjsize = cvSize(835, 165); //角标裁剪框的大小宽为835象素高为165象素
IplImage* imgjbcj = cvCreateImage(jbcjsize, img->depth, img->nChannels);
uchar *imgjbcjdata = (uchar *)imgjbcj->imageData;
int jbcjstep = imgjbcj->widthStep;
int jbcjchannels = imgjbcj->nChannels;
for (i = 0; i<165; i++)
for (j = 0; j<835; j++)
imgjbcjdata[i*jbcjstep + j*jbcjchannels] = data[(i + jbi)*step + (j + jbj)*channels];
for (i = 0; i<165; i = i + 2)
{
imgjbsbdata[(i + jbi)*step + jbj*channels] = 0;
imgjbsbdata[(i + jbi)*step + (jbj + 835)*channels] = 0;
}
for (j = 0; j<835; j = j + 2)
{
imgjbsbdata[jbi*step + (j + jbj)*channels] = 0;
imgjbsbdata[(jbi + 165)*step + (j + jbj)*channels] = 0;
}
return imgjbcj;
}

View File

@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
/**
根据学生信息创建文件路径,用于文件读取
@变量 date 考试日期
@变量 subject 考试科目
@变量 stuNum 考号
@返回值 返回生成的文件路径
*/
string CrPath(string date, string subject, string stuNum)
{
string temp = "Z:/"; temp += date; temp += "/";
temp += subject.substr(0, 4); temp += "/";
temp += stuNum; temp += ".jpg";
return temp;
}

View File

@@ -0,0 +1,179 @@
#import "C:\Program Files\Common Files\System\ado\msado15.dll"\
no_namespace rename("EOF","EndOfFile")
#include <vector>
#include <string>
#include <iostream>
#include <windows.h>
#include <iomanip>
#include <stdio.h>
using namespace std;
string g_db_hostName = "192.168.200.97"; /*全局变量 服务器ip或名称*/
string g_db_dBName = "purple"; /*全局变量 服务器ODBC数据源*/
string g_db_userName = "BJSH"; /*全局变量 服务器用户名*/
string g_db_password = "bjshadmin"; /*全局变量 服务器密码*/
/*调试数据*/
//string g_db_hostName = "localhost"; /*全局变量 服务器ip或名称*/
//string g_db_dBName = "yanshuaishuai"; /*全局变量 服务器ODBC数据源*/
//string g_db_userName = "yannsy"; /*全局变量 服务器用户名*/
//string g_db_password = "123456"; /*全局变量 服务器密码*/
string g_db_qurry_start = "200906"; /*全局变量 数据库查询_开始日期*/
string g_db_qurry_end = "201610"; /*全局变量 数据库查询_结束日期*/
string g_db_qurry_zone = "0"; /*全局变量 数据库查询_特定区域*/
string g_db_qurry_stu_num = "0"; /*全局变量 数据库查询_特定考号*/
bool g_db_qurry_all = true; /*全局变量 数据库查询_查询全部标记*/
_ConnectionPtr p_conn; /*全局变量 连接对象*/
_RecordsetPtr p_recordset; /*全局变量 记录集对象*/
_CommandPtr p_cmd; /*全局变量 操作集对象*/
string str_conn; /*全局变量 连接字符串设置*/
/**
程序功能: 根据string类的stu【存储学号】搜索出所有此人的考试信息,并分别存储在不同的变量中
@变量 stuNum 学号
@变量 date<vector> 考试时间
@变量 subject<vector> 考试科目
@变量 stuNum<vector> 考号
@返回值 成功1 失败0
*/
int DbImg(string stuNum, vector<string>& dateVec, vector<string>& subjectVec, vector<string>& stuNum2)//搜寻图片
{
/*字符转换,方便使用*/
string userName(g_db_userName.c_str());
string password(g_db_password.c_str());
string hostName(g_db_hostName.c_str());
string dBName(g_db_dBName.c_str());
//构造查询语句 下句注释是sql语句需要构造成这种类型
/*select KS_ZKZ, KSSJ, TJ_KC_DM from ZK.T_BYSQ_KS_KC WHERE KSSJ between '200907' and '201510' and KS_ZKZ = 010207203867*/
/*string sql = "select KS_ZKZ2, KSSJ, TJ_KC_DM from ZK.T_BYSQ_KS_KC WHERE KSSJ between '200907' and '201504' AND KS_ZKZ = ";*/
string sql = "select KS_ZKZ2, KSSJ, TJ_KC_DM from ZK.T_BYSQ_KS_KC WHERE KSSJ between ";
sql += g_db_qurry_start;
sql += " and ";
sql += g_db_qurry_end;
sql += "AND KS_ZKZ =";
sql += stuNum.c_str();
_bstr_t _vstr_sql(sql.c_str());/* 转换string为_variant_t */
::CoInitialize(NULL);//初始化com组件
/*创建、打开连接*/
try{
p_conn.CreateInstance("ADODB.Connection");//创建连接
p_recordset.CreateInstance("ADODB.Recordset");//创建结果集,也就是实例化
p_cmd.CreateInstance("ADODB.Command");
p_conn->CursorLocation = adUseClient; //存储过程同时返回记录集和返回值
p_conn->Open(_bstr_t(str_conn.c_str()), _bstr_t(userName.c_str()), _bstr_t(password.c_str()), adConnectUnspecified);
p_cmd.CreateInstance("ADODB.Command");
p_cmd->ActiveConnection = p_conn;
HRESULT hr = p_recordset->Open(_bstr_t(_vstr_sql),//执行sq语句查询一个学生的所有考试信息
p_conn.GetInterfacePtr(),
adOpenStatic,
adLockOptimistic,
adCmdText);
//将结果集输出到三个vector变量中
if (p_recordset->RecordCount < 1)//结果集为空
{
return 1;//没有信息,直接跳过这个人
}
do{ //将结果集输出到三个vector变量中
dateVec.push_back((string)(_bstr_t)(p_recordset->Fields->GetItem(_variant_t("KSSJ"))->GetValue()));
subjectVec.push_back((string)(_bstr_t)(p_recordset->Fields->GetItem(_variant_t("TJ_KC_DM"))->GetValue()));
stuNum2.push_back((string)(_bstr_t)(p_recordset->Fields->GetItem(_variant_t("KS_ZKZ2"))->GetValue()));
p_recordset->MoveNext();
} while (!p_recordset->EndOfFile);
}
catch (_com_error e){ return 0; }
/*关闭查询*/
try { ::CoUninitialize(); }
catch (_com_error e){ /*cout << "qurry:" << e.ErrorInfo() << endl;*/ }
return 1;
}
/**
程序功能: 更新学生数据库信息,根据学生的鉴定结果,将结果输出到数据库中
@变量 stuNum学号
@变量 subject考试科目
@变量 flagCheat作弊标记
@返回值 成功1失败0
*/
int DbUpdate(string stuNum, vector<string> dateVec,
vector<string> subjectVec, vector<string> stuNum2,
vector<string> flagVec)
{
/*字符转换,方便使用*/
string userName(g_db_userName.c_str());
string password(g_db_password.c_str());
string hostName(g_db_hostName.c_str());
string dBName(g_db_dBName.c_str());
/*更新字串设置*/
int count = subjectVec.size();
vector<string > sqlKC; //课程表:作弊第一字段
int ci = 0; //循环
string flagSQL = "0";//标记 机器审核结果表
for (ci = 0; ci < count; ++ci)
{
if (flagVec[ci] == "1")
flagSQL = "1";
/*作弊的*/
string sqlKC1 = "UPDATE ZK.T_BYSQ_KS_KC SET BJSH_JG_JQ =";//天津_课程_代码
sqlKC1 += flagVec[ci].c_str();
sqlKC1 += " WHERE KS_ZKZ2=";
sqlKC1 += stuNum2[ci].c_str();
sqlKC1 += " AND TJ_KC_DM=";
sqlKC1 += subjectVec[ci].c_str();
sqlKC1 += " AND KSSJ=";
sqlKC1 += dateVec[ci].c_str();
sqlKC1 += " AND KS_ZKZ=";
sqlKC1 += stuNum.c_str();
sqlKC.push_back(sqlKC1);
}
::CoInitialize(NULL);//初始化com组件
/*更新数据库表*/
try{
p_conn.CreateInstance("ADODB.Connection");//创建连接
p_recordset.CreateInstance("ADODB.Recordset");//创建结果集,也就是实例化
p_cmd.CreateInstance("ADODB.Command");
p_conn->CursorLocation = adUseClient; //存储过程同时返回记录集和返回值
p_conn->Open(_bstr_t(str_conn.c_str()), _bstr_t(userName.c_str()), _bstr_t(password.c_str()), adConnectUnspecified);
p_cmd->ActiveConnection = p_conn;
for (ci = 0; ci < count; ++ci)
{
p_recordset->Open(_bstr_t(sqlKC[ci].c_str()),//更新第二条
p_conn.GetInterfacePtr(),
adOpenStatic,
adLockOptimistic,
adCmdText);
}
}
catch (_com_error e){ return 0; }
/*关闭查询*/
try {
::CoUninitialize();
}
catch (_com_error e){ }
return 1;
}

View File

@@ -0,0 +1,13 @@
// HWCV.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

View File

@@ -0,0 +1,3 @@
LIBRARY "HWCV"
EXPORTS HWCV
EXPORTS TEST

View File

@@ -0,0 +1,144 @@
# Microsoft Developer Studio Project File - Name="HWCV" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=HWCV - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "HWCV.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "HWCV.mak" CFG="HWCV - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "HWCV - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "HWCV - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "HWCV - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HWCV_EXPORTS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /G4 /Gz /Zp4 /MD /W3 /GX /O2 /I "OpenCV\cv\include" /I "OpenCV\otherlibs\highgui" /I "OpenCV\cxcore\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HWCV_EXPORTS" /U "OpenCV\\lib" /FR /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x804 /d "NDEBUG"
# ADD RSC /l 0x804 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 FreeImage.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib /nologo /dll /machine:I386
!ELSEIF "$(CFG)" == "HWCV - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HWCV_EXPORTS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HWCV_EXPORTS" /Yu"stdafx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x804 /d "_DEBUG"
# ADD RSC /l 0x804 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib FreeImage.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "HWCV - Win32 Release"
# Name "HWCV - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\binary.cpp
# End Source File
# Begin Source File
SOURCE=.\Cjbsb.cpp
# End Source File
# Begin Source File
SOURCE=.\outline.cpp
# End Source File
# Begin Source File
SOURCE=.\outlinefeature.cpp
# End Source File
# Begin Source File
SOURCE=.\read_scanf.cpp
# End Source File
# Begin Source File
SOURCE=.\segmentation.cpp
# End Source File
# Begin Source File
SOURCE=.\singlefeature.cpp
# End Source File
# Begin Source File
SOURCE=.\Thinner.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\HWCV.def
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "HWCV"=".\HWCV.dsp" - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,16 @@
<html>
<body>
<pre>
<h1>Build Log</h1>
<h3>
--------------------Configuration: HWCV - Win32 Release--------------------
</h3>
<h3>Command Lines</h3>
<h3>Results</h3>
HWCV.dll - 0 error(s), 0 warning(s)
</pre>
</body>
</html>

View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<SccProjectName />
<SccLocalPath />
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>.\Debug\</OutDir>
<IntDir>.\Debug\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>.\Release\</OutDir>
<IntDir>.\Release\</IntDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<FunctionLevelLinking>false</FunctionLevelLinking>
<Optimization>Disabled</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<MinimalRebuild>true</MinimalRebuild>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HWCV_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>.\Debug\</AssemblerListingLocation>
<PrecompiledHeaderOutputFile>.\Debug\HWCV.pch</PrecompiledHeaderOutputFile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<ObjectFileName>.\Debug\</ObjectFileName>
<ProgramDataBaseFileName>.\Debug\</ProgramDataBaseFileName>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
</ClCompile>
<Midl>
<SuppressStartupBanner>true</SuppressStartupBanner>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TypeLibraryName>.\Debug\HWCV.tlb</TypeLibraryName>
<MkTypLibCompatible>true</MkTypLibCompatible>
<TargetEnvironment>Win32</TargetEnvironment>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\Debug\HWCV.bsc</OutputFile>
</Bscmake>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<LinkDLL>true</LinkDLL>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OutputFile>.\Debug\HWCV.dll</OutputFile>
<ImportLibrary>.\Debug\HWCV.lib</ImportLibrary>
<AdditionalDependencies>odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\HWCV.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<StringPooling>true</StringPooling>
<FunctionLevelLinking>true</FunctionLevelLinking>
<Optimization>MaxSpeed</Optimization>
<SuppressStartupBanner>true</SuppressStartupBanner>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>OpenCV\cv\include;OpenCV\otherlibs\highgui;OpenCV\cxcore\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;HWCV_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<UndefinePreprocessorDefinitions>OpenCV\\lib;%(UndefinePreprocessorDefinitions)</UndefinePreprocessorDefinitions>
<AssemblerListingLocation>.\Release\</AssemblerListingLocation>
<BrowseInformation>true</BrowseInformation>
<PrecompiledHeaderOutputFile>.\Release\HWCV.pch</PrecompiledHeaderOutputFile>
<PrecompiledHeader>
</PrecompiledHeader>
<ObjectFileName>.\Release\</ObjectFileName>
<ProgramDataBaseFileName>.\Release\</ProgramDataBaseFileName>
<CallingConvention>StdCall</CallingConvention>
<StructMemberAlignment>4Bytes</StructMemberAlignment>
</ClCompile>
<Midl>
<SuppressStartupBanner>true</SuppressStartupBanner>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TypeLibraryName>.\Release\HWCV.tlb</TypeLibraryName>
<MkTypLibCompatible>true</MkTypLibCompatible>
<TargetEnvironment>Win32</TargetEnvironment>
</Midl>
<ResourceCompile>
<Culture>0x0804</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
<OutputFile>.\Release\HWCV.bsc</OutputFile>
</Bscmake>
<Link>
<SuppressStartupBanner>true</SuppressStartupBanner>
<LinkDLL>true</LinkDLL>
<SubSystem>Console</SubSystem>
<OutputFile>.\Release\HWCV.dll</OutputFile>
<ImportLibrary>.\Release\HWCV.lib</ImportLibrary>
<AdditionalDependencies>FreeImage.lib;cxcore.lib;cv.lib;ml.lib;cvaux.lib;highgui.lib;cvcam.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>.\HWCV.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="binary.cpp" />
<ClCompile Include="Cjbsb.cpp" />
<ClCompile Include="Cword.cpp" />
<ClCompile Include="getFiles.cpp" />
<ClCompile Include="getFloders.cpp" />
<ClCompile Include="getType.cpp" />
<ClCompile Include="gif2ipl.cpp" />
<ClCompile Include="outline.cpp" />
<ClCompile Include="outlinefeature.cpp" />
<ClCompile Include="read_scanf.cpp" />
<ClCompile Include="segmentation.cpp" />
<ClCompile Include="singlefeature.cpp" />
<ClCompile Include="Thinner.cpp" />
<ClCompile Include="worddivide.cpp" />
<ClCompile Include="wordrecognize.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Cword.h" />
<ClInclude Include="FreeImage.h" />
<ClInclude Include="Point.h" />
<ClInclude Include="Thinner.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="HWCV.def" />
<CustomBuild Include="ReadMe.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{5132bb21-0ec3-411b-8a1b-91890205e9e8}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{0146cd25-bd07-4b86-90b5-8a28a4b87af1}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{7d418a22-acbe-42ad-9b5f-bba6e2b4b2be}</UniqueIdentifier>
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="binary.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Cjbsb.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Cword.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="getFiles.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="getFloders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="getType.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="gif2ipl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="outline.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="outlinefeature.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="read_scanf.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="segmentation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="singlefeature.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Thinner.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="worddivide.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wordrecognize.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Cword.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FreeImage.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Point.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Thinner.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="HWCV.def">
<Filter>Header Files</Filter>
</CustomBuild>
<CustomBuild Include="ReadMe.txt" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
class Point{
private:
public:
int x;
int y;
void setpoint(int a,int b){x=a;y=b;}
};

View File

@@ -0,0 +1,41 @@
========================================================================
DYNAMIC LINK LIBRARY : HWCV
========================================================================
AppWizard has created this HWCV DLL for you.
This file contains a summary of what you will find in each of the files that
make up your HWCV application.
HWCV.dsp
This file (the project file) contains information at the project level and
is used to build a single project or subproject. Other users can share the
project (.dsp) file, but they should export the makefiles locally.
HWCV.cpp
This is the main DLL source file.
When created, this DLL does not export any symbols. As a result, it
will not produce a .lib file when it is built. If you wish this project
to be a project dependency of some other project, you will either need to
add code to export some symbols from the DLL so that an export library
will be produced, or you can check the "doesn't produce lib" checkbox in
the Linker settings page for this project.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named HWCV.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// HWCV.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@@ -0,0 +1,24 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__0B833134_257D_4F21_9707_24C780138809__INCLUDED_)
#define AFX_STDAFX_H__0B833134_257D_4F21_9707_24C780138809__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Insert your headers here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__0B833134_257D_4F21_9707_24C780138809__INCLUDED_)

View File

@@ -0,0 +1,186 @@
//**************************************************************************
//Thinner.cpp
//细化算法实现文件
//**************************************************************************
//#include "StdAfx.h"
#include <stdlib.h>
#include <malloc.h>
#include "Thinner.h"
#include <stdio.h>
void beforethin(unsigned char *ip, unsigned char *jp, unsigned long lx, unsigned long ly){
//void beforethin(char *ip, char *jp,
// unsigned long lx, unsigned long ly)
unsigned long i,j;
// printf("--Thinner_beforeThin--");
for(i=0; i<ly; i++){
for(j=0; j<lx; j++){
//这里要视前景是白点还是黑点而定,可以改动
//如果前景是白点,就是这样;反之反过来
//jp[i*lx+j]=ip[i*lx+j];
/* jp[i*lx+j]=255;*/
if(ip[i*lx+j]>0)
jp[i*lx+j]=0;
else
jp[i*lx+j]=255;
}
}
}
/////////////////////////////////////////////////////////////////////////
//Rosenfeld细化算法
//功能:对图象进行细化
//参数image代表图象的一维数组
// lx图象宽度
// ly图象高度
// 无返回值
void ThinnerRosenfeld(void *image, unsigned long lx, unsigned long ly){
char *f, *g;
char n[10];
char a[5] = {0, -1, 1, 0, 0};
char b[5] = {0, 0, 0, 1, -1};
char nrnd, cond, n48, n26, n24, n46, n68, n82, n123, n345, n567, n781;
short k, shori;
unsigned long i, j;
long ii, jj, kk, kk1, kk2, kk3, size;
// printf("--Thinner_Rosenfeld--");
size = (long)lx * (long)ly;
g = (char *)malloc(size);
if(g==NULL){
printf("error in alocating mmeory!\n");
return;
}
f = (char *)image;
for(kk=0l; kk<size; kk++){
g[kk] = f[kk];
}
do{
shori = 0;
for(k=1; k<=4; k++){
for(i=1; i<lx-1; i++){
ii = i + a[k];
for(j=1; j<ly-1; j++){
kk = i*ly + j;
if(!f[kk])
continue;
jj = j + b[k];
kk1 = ii*ly + jj;
if(f[kk1])
continue;
kk1 = kk - ly -1;
kk2 = kk1 + 1;
kk3 = kk2 + 1;
n[3] = f[kk1];
n[2] = f[kk2];
n[1] = f[kk3];
kk1 = kk - 1;
kk3 = kk + 1;
n[4] = f[kk1];
n[8] = f[kk3];
kk1 = kk + ly - 1;
kk2 = kk1 + 1;
kk3 = kk2 + 1;
n[5] = f[kk1];
n[6] = f[kk2];
n[7] = f[kk3];
nrnd = n[1] + n[2] + n[3] + n[4]
+n[5] + n[6] + n[7] + n[8];
if(nrnd<=1)
continue;
cond = 0;
n48 = n[4] + n[8];
n26 = n[2] + n[6];
n24 = n[2] + n[4];
n46 = n[4] + n[6];
n68 = n[6] + n[8];
n82 = n[8] + n[2];
n123 = n[1] + n[2] + n[3];
n345 = n[3] + n[4] + n[5];
n567 = n[5] + n[6] + n[7];
n781 = n[7] + n[8] + n[1];
if(n[2]==1 && n48==0 && n567>0){
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[6]==1 && n48==0 && n123>0) {
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[8]==1 && n26==0 && n345>0){
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[4]==1 && n26==0 && n781>0) {
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[5]==1 && n46==0){
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[7]==1 && n68==0){
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[1]==1 && n82==0){
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
if(n[3]==1 && n24==0){
if(!cond)
continue;
g[kk] = 0;
shori = 1;
continue;
}
cond = 1;
if(!cond)
continue;
g[kk] = 0;
shori = 1;
}
}
for(i=0; i<lx; i++){
for(j=0; j<ly; j++){
kk = i*ly + j;
f[kk] = g[kk];
}
}
}
}while(shori);
free(g);
}

View File

@@ -0,0 +1,11 @@
//***************************************************************************
// 文件Thinner.h
// 功能:四种不同的细化算法
//***************************************************************************
void beforethin(unsigned char *ip,unsigned char *jp, unsigned long lx, unsigned long ly);
void ThinnerHilditch(void *image, unsigned long lx, unsigned long ly);
void ThinnerPavlidis(void *image, unsigned long lx, unsigned long ly);
void ThinnerRosenfeld(void *image, unsigned long lx, unsigned long ly);
//注意该函数lWidth应该是Height
//BOOL WINAPI ThiningDIBSkeleton (LPSTR lpDIBBits, LONG lWidth, LONG lHeight);

View File

@@ -0,0 +1,46 @@
/* 程序名binary.c
功能:读入图像文件,进行二值化
*/
#include <cv.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>
int* binary(IplImage* img,int bithro)
{
int height,width,step,channels;
uchar *data;
int i,j;
static int black[1000]; //C语言不提倡返回一个局部变量的地址以外的功能所以你必须定义的局部变量如静态变量。
/* 获取图像信息*/
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
/*二值化,并统计黑像素的个数*/
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)//对图像每个点进行二值化,原值为128
data[i*step+j*channels]=(data[i*step+j*channels]>bithro)?255:0;
}
/*计算每一行的黑像素个数*/
int tempBlackPixel=0;
memset(black,0,1000); //##初始化内存这里用做清零black数组
for(i=height-1;i>0;i--)
{
for(int j=0;j<width;j++)
{
if(data[i*step+j*channels]==0) //计算黑色的像素数
tempBlackPixel+=1;
}
black[height-i]=tempBlackPixel; //black记录黑色像素数
tempBlackPixel=0;
}
//二值化,并统计黑像素的个数**********
return black;
}

View File

@@ -0,0 +1,28 @@
/* 程序名cutName.cpp
功能:裁剪文件名
*/
#include<io.h>
#include <stdio.h>
#include<vector>
#include<iostream>
using namespace std;
#include <string.h>
int cutName(vector<string> &files){
vector<string> files_temp;
int num=files.size();
int i=0;
for(i=0;i<num;++i){
string temp=files[i].c_str();
temp= temp.substr(34,temp.length()-4);
files_temp.push_back(temp);
}
files.clear();
for(i=0;i<num;++i)
files.push_back(files_temp[i].c_str());
files_temp.clear();
return 1;
}

View File

@@ -0,0 +1,47 @@
/* 程序名outline.c
功能:输入文字图像。得到相应的轮廓图
*/
#include <cv.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>
IplImage* outline(IplImage* imgbj){
/*定义变量*/
int i,j;
int height,width,step,channels;
uchar *data;
/*定义新的图像*/
IplImage* imglk = cvCreateImage(cvGetSize(imgbj),imgbj->depth,imgbj->nChannels);
/* 获取图像信息*/
height = imgbj->height;
width = imgbj->width;
step = imgbj->widthStep;
channels = imgbj->nChannels;
data = (uchar *)imgbj->imageData;
// printf("--outline--");
for(j=0;j<height;j++){
for(int i=0;i<width;i++){
imglk->imageData[j*step+i*channels]=255;
}
for( i=0;i<width-1;i++){
if(data[j*step+(i+1)*channels]-data[j*step+i*channels]==255) //竖线右侧框
imglk->imageData[j*step+i*channels]=0;
else if(data[j*step+i*channels]-data[j*step+(i+1)*channels]==255) //竖线左侧框
imglk->imageData[j*step+(i+1)*channels]=0;
}
}
for(i=0;i<width;i++){
for(j=0;j<height-1;j++){
if(data[j*step+i*channels]-data[(j+1)*step+i*channels]==255) //横线下侧框
imglk->imageData[(j+1)*step+i*channels]=0;
else if(data[(j+1)*step+i*channels]-data[j*step+i*channels]==255) //横线上侧框
imglk->imageData[j*step+i*channels]=0;
}
}
return imglk;
}

View File

@@ -0,0 +1,209 @@
/* 程序名outline.c
功能:输入文字轮廓图,返回相应的轮廓特征值
*/
#include <cv.h>
#include <highgui.h>
#include <stdlib.h>
#include <stdio.h>
#include "Point.h"
//输入文字的轮廓图像,返回相应的轮廓特征值
int outlinefeature(IplImage* imglk,int feature[ ][50]){
//定义变量
int i,j;
int height,width,step,channels;
uchar *data;
int feat[50][50]={0}; //特征值初始化
Point featblk[32]; //标记相同H的黑点坐标
int featk; //标记相同H的黑点数目
int m; //for 里面的变量
// printf("--outlinefeature--");
// 获取图像信息
height = imglk->height;
width = imglk->width;
step = imglk->widthStep;
channels = imglk->nChannels;
data = (uchar *)imglk->imageData;
//初始化特征矩阵 最大值为47 非空的特征字有1081个
int outllab[9][9]={\
{3,37,10,36,2,35,9,34,1},{38,3,21,20,2,19,18,1,33},\
{11,22,3,10,2,9,1,17,8},{39,23,11,3,2,1,8,16,32},\
{4,4,4,4,0,0,0,0,0},{40,24,12,5,6,7,15,31,47},\
{12,25,5,13,6,14,7,30,15},{41,5,26,27,6,28,29,7,46},\
{5,42,13,43,6,44,14,45,7}};
for(i=4;i<=width-5;i++){
for(j=4;j<=height-5;j++){
if(data[j*step+i*channels]==0){
//**************H=1
memset(featblk, 0, sizeof(Point)*32); //归零
featk=0;
if(data[j*step+(i+1)*channels]==0){ //右侧点
featblk[featk].x=i+1;
featblk[featk].y=j;
featk++;
}
for(m=i+1;m>=i-1;m--){ //上排点
if(data[(j-1)*step+m*channels]==0) {
featblk[featk].x=m;
featblk[featk].y=j-1;
featk++;
}
}
if(data[j*step+(i-1)*channels]==0){ //左侧点
featblk[featk].x=i-1;
featblk[featk].y=j;
featk++;
}
for(m=i-1;m<=i+1;m++) { //下排点
if(data[(j+1)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j+1;
featk++;
}
}
//统计特征点
if(featk>=2){
for(m=1;m<=featk-1;m++){
feat[outllab[featblk[m-1].x-i+4][featblk[m-1].y-j+4]][outllab[featblk[m].x-i+4][featblk[m].y-j+4]]++;
}
}
//H=1*******************
//*********************H=2
memset(featblk, 0, sizeof(Point)*32); //归零
featk=0;
for(m=j+1;m>=j-2;m--){
if(data[m*step+(i+2)*channels]==0){ //右排点
featblk[featk].x=i+2;
featblk[featk].y=m;
featk++;
}
}
for(m=i+1;m>=i-2;m--){ //上排点
if(data[(j-2)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j-2;
featk++;
}
}
for(m=j-1;m<=j+2;m++){ //左侧点
if(data[m*step+(i-2)*channels]==0){
featblk[featk].x=i-2;
featblk[featk].y=m;
featk++;
}
}
for(m=i-1;m<=i+2;m++){ //下排点
if(data[(j+2)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j+2;
featk++;
}
}
//统计特征点
if(featk>=2){
for(m=1;m<=featk-1;m++){
feat[outllab[featblk[m-1].x-i+4][featblk[m-1].y-j+4]][outllab[featblk[m].x-i+4][featblk[m].y-j+4]]++;
}
}
//H=2********************
//*********************H=3
memset(featblk, 0, sizeof(Point)*32); //归零
featk=0;
for(m=j+2;m>=j-3;m--){
if(data[m*step+(i+3)*channels]==0){ //右排点
featblk[featk].x=i+3;
featblk[featk].y=m;
featk++;
}
}
for(m=i+2;m>=i-3;m--){ //上排点
if(data[(j-3)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j-3;
featk++;
}
}
for(m=j-2;m<=j+3;m++){ //左侧点
if(data[m*step+(i-3)*channels]==0){
featblk[featk].x=i-3;
featblk[featk].y=m;
featk++;
}
}
for(m=i-2;m<=i+3;m++){ //下排点
if(data[(j+3)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j+3;
featk++;
}
}
//统计特征点
if(featk>=2){
for(m=1;m<=featk-1;m++){
feat[outllab[featblk[m-1].x-i+4][featblk[m-1].y-j+4]][outllab[featblk[m].x-i+4][featblk[m].y-j+4]]++;
}
}
//H=3********************
//*********************H=4
memset(featblk, 0, sizeof(Point)*32); //归零
featk=0;
for(m=j+3;m>=j-4;m--){
if(data[m*step+(i+4)*channels]==0){ //右排点
featblk[featk].x=i+4;
featblk[featk].y=m;
featk++;
}
}
for(m=i+3;m>=i-4;m--) { //上排点
if(data[(j-4)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j-4;
featk++;
}
}
for(m=j-3;m<=j+4;m++){ //左侧点
if(data[m*step+(i-4)*channels]==0){
featblk[featk].x=i-4;
featblk[featk].y=m;
featk++;
}
}
for(m=i-3;m<=i+4;m++){ //下排点
if(data[(j+4)*step+m*channels]==0){
featblk[featk].x=m;
featblk[featk].y=j+4;
featk++;
}
}
//统计特征点
if(featk>=2){
for(m=1;m<=featk-1;m++){
feat[outllab[featblk[m-1].x-i+4][featblk[m-1].y-j+4]][outllab[featblk[m].x-i+4][featblk[m].y-j+4]]++;
}
}
//H=4***********************
}// if
} //for j
} //for i
//****注最终特征值为feat(x,y)+feat(y,x)放入feat(x,y)中x<y
for(i=1;i<50;i++)
for(j=0;j<i;j++){
feat[j][i]=feat[i][j]+feat[j][i];
feat[i][j]=0;
}
memcpy(feature,feat,2500*4); //int有四个字节
// printf("轮廓特征值计算完成\n");
return 0;
}

View File

@@ -0,0 +1,30 @@
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int read_scanf(const string &filename,const int &cols,vector<double *> &_vector){
// 功能将filename 中的数据共cols列读取到_vector中_vector可视为二维数组
FILE *fp=fopen(filename.c_str(),"r");//打开并读取文件
bool flag=true;
int i=0;
// printf("--read_scanf--");
if(!fp){ cout<<"File open error!\n"; return 0; }
while(flag){
double *point=new double[cols];
for(i=0;i<cols;i++){ //读取数据存在_vector[cols]中
if(EOF==fscanf(fp,"%lf",&point[i])) {
flag=false;break;
}
if(EOF==fgetc(fp)) {
flag=false;i++;break;
}
}
if(cols==i)
_vector.push_back(point);
}
fclose(fp);
return 1;
}

View File

@@ -0,0 +1,199 @@
#pragma once
#ifdef WIN32 //屏蔽VC6对STL的一些不完全支持造成
#pragma warning (disable: 4514 4786)
#endif
#include <time.h>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <cv.h>
#include<io.h> //下面的5个用于读取文件夹下的所有文件名
#include<vector>
#include <string.h>
#include<windows.h> //用于弹出提示框,,,切记!当调用<windows.h>时不要调用MFCAfx.h)
#include<string.h>
using namespace std;
int* binary(IplImage* img,int bithro); //二值化图像
int outlinefeature(IplImage* imglk,int feature[ ][50]); //计算图像的轮廓特征值
int read_scanf(const string &filename,const int &cols,vector<double *> &_vector); //读取已经存好的特征值
IplImage* Cjbsb(IplImage* img,IplImage* imgjbsb,int jbwhite,int jbblack); //图像角标识别
IplImage* outline(IplImage* imgbj); //计算图像对应的轮廓图
IplImage* singlefeature(char* path,int feature[ ][50]); //得出单个文件的特征值
char *fo = "H:\\logs_dll_check_only.txt";
char rec[2000] = "\n结果集合为空:";
FILE *fpzz3 = NULL;//需要注意
extern "C" _declspec(dllexport) char * __stdcall WINAPI TEST(char *fpname1){
return fpname1;//总文件夹的路径
}
extern "C" _declspec(dllexport) char * __stdcall WINAPI HWCV(char *fpname1,char *dest)
{
int conti = 1;
int size, i, ii, jj, feature[50][50][30] = { 0 }, featureall;
double featurep[50][50][30] = { 0 },bzcu[50][50] = { 0 }, bzckesa[50][50] = { 0 }, wcd[30] = { 0 };
int featx[50][50] = { 0 }, featdif[30] = { 0 }, maxi; float maxx = 0; //最大特征值的标号与值
int xyimgnum = 0; //嫌疑图片的数目
char str[80]; //存储地址
/*变量定义*/
vector<string> suspict; //记录嫌疑图片地址
vector<float> suspict_wcd;
vector<string> files; //存储该生所有考试文件路径
vector<string> dateVec, subjectVec, stuNum2;
vector<int> flagVec;//记录查到的学生的所有考试信息
files.push_back("D:\\tupian\\201110\\0534\\010209400748.jpg");
files.push_back("D:\\tupian\\201010\\0665\\010209400748.jpg");
files.push_back("D:\\tupian\\201606\\0668\\010209400748.jpg");
files.push_back("D:\\tupian\\201101\\0799\\010209400748.jpg");
files.push_back("D:\\tupian\\201101\\0883\\010209400748.jpg");
files.push_back("D:\\tupian\\201201\\0884\\010209400748.jpg");
files.push_back("D:\\tupian\\201107\\0885\\010209400748.jpg");
files.push_back("D:\\tupian\\201307\\0886\\010209400748.jpg");
files.push_back("D:\\tupian\\201307\\0887\\010209400748.jpg");
files.push_back("D:\\tupian\\201107\\0888\\010209400748.jpg");
files.push_back("D:\\tupian\\201404\\4685\\010209400748.jpg");
files.push_back("D:\\tupian\\201104\\1180\\010209400748.jpg");
files.push_back("D:\\tupian\\201110\\1181\\010209400748.jpg");
files.push_back("D:\\tupian\\201510\\0359\\080215203444.jpg");
files.push_back("D:\\tupian\\201212\\0101\\010209400748.jpg");
files.push_back("D:\\tupian\\201606\\4927\\010209400748.jpg");
size = files.size(); //图像的数目
//开始对每一张图片进行处理
for (i = 0; i < size; i++)
{
memset(str, 0, sizeof(str));
memset(featx, 0, sizeof(featx));
memset(bzcu, 0, sizeof(bzcu));
strcpy(str, files[i].c_str());
singlefeature(str, featx); //featx[][50]
featureall = 0; //图像特征值和的初始化
for (ii = 0; ii < 48; ii++) //将featx存起来,回头看能不能用函数换掉
for (jj = ii + 1; jj < 47; jj++)
{
feature[ii][jj][i] = featx[ii][jj];
featureall = featureall + featx[ii][jj];
}
//求轮廓方向特征featurep式(5) 与标准差中的u的和
for (ii = 0; ii < 48; ii++)
for (jj = ii + 1; jj < 47; jj++)
{
featurep[ii][jj][i] = (double)featx[ii][jj] / featureall;
bzcu[ii][jj] += (double)featx[ii][jj] / featureall * 1000; //标准差的值过小,进行放大1
}
}
//处理完一个人的每一张图片后
//----------------------------------------------------------//
for (ii = 0; ii < 48; ii++)//求标准差中的u
for (jj = ii + 1; jj < 47; jj++)
bzcu[ii][jj] = bzcu[ii][jj] / size;
/*将标准差中的kesa加载进来*/
string bzcfile = "D:/Xiangmu/Img/bzc/bzc.txt";
//txt文件中有47列
int bzccolumns = 47;
vector<double *> output_bzc;
if (!read_scanf(bzcfile, bzccolumns, output_bzc)) return 0;
//output_vector可视为二维数组;输出数组元素:
//int rows=output_bzc.size();
for (ii = 0; ii < 48; ii++)
for (jj = ii + 1; jj < 47; jj++)
bzckesa[ii][jj] = output_bzc[ii][jj];
//求相似性就是带权卡方wcd
for (i = 0; i < size; i++)
for (ii = 0; ii < 48; ii++)
for (jj = ii + 1; jj < 47; jj++)
if (featurep[ii][jj][i] * featurep[ii][jj][conti] != 0 && bzckesa[ii][jj] != -1)
wcd[i] += pow((featurep[ii][jj][i] - featurep[ii][jj][conti]), 2) / ((featurep[ii][jj][i] + featurep[ii][jj][conti])*bzckesa[ii][jj]);
//求卡方距离的最大值
for (i = 0; i < size; i++)
{
if (maxx < wcd[i]){ maxx = wcd[i]; maxi = i; }
if (wcd[i] > 0.12)
{
xyimgnum++;
suspict.push_back(files[i].c_str());
suspict_wcd.push_back(wcd[i]);
flagVec.push_back(1);//嫌疑标记
}else
{
flagVec.push_back(0);
}
}
/*存储文件记录*/
//char* fpname = "C:/Users/闫帅帅/Desktop/result2.txt";
//char record[2400] = { 0 };
//FILE* fpzz = NULL;//需要注意
fpzz3 = fopen(fo, "a"); //创建文件 //a
if (NULL == fpzz3) return "ERR";//要返回错误代码
fprintf(fpzz3, rec); //从控制台中读入并在文本输出
fclose(fpzz3);
fpzz3 = NULL;//需要指向空,否则会指向原打开文件地址
//将结果存入txt
memset(rec, 0, sizeof(rec));
strcpy(rec, "图片总数为:");
char pic_num[20];
_itoa(size, pic_num, 10);
strcat(rec, pic_num);
if (xyimgnum > 0)
{
strcat(rec, "\n");
for (i = 0; i < xyimgnum; i++)
{
strcat(rec, "\t");
strcat(rec, suspict[i].c_str());
strcat(rec, "\t");
char a[20];
sprintf(a, "%g", suspict_wcd[i]);
strcat(rec, a);
strcat(rec, "\n");
}
}
else strcat(rec, "\t没有嫌疑图像!\n");
fpzz3 = fopen(fo, "a"); //创建文件 //a
if (NULL == fpzz3) return "ERR";//要返回错误代码
fprintf(fpzz3, rec); //从控制台中读入并在文本输出
fclose(fpzz3);
fpzz3 = NULL;//需要指向空,否则会指向原打开文件地址
suspict.clear();
suspict_wcd.clear();
output_bzc.clear();
//memset(record, 0, 2400);
memset(feature, 0, sizeof(feature));
memset(featurep, 0, sizeof(featurep));
memset(bzckesa, 0, sizeof(bzckesa));
memset(wcd, 0, sizeof(wcd));
memset(featdif, 0, sizeof(featdif));
char out[100]="成功!\n";
strcat(out, fpname1);
sprintf(dest, out );
return "return_OK";
}

View File

@@ -0,0 +1,163 @@
/* 程序名singlefeature.c
功能:分总程序:读入图像文件,得出单个文件的特征值
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
#include "Point.h"
#include<io.h>
#include<vector>
#include<iostream>
#include <string.h>
#include <direct.h>
#include"Thinner.h"
using namespace std;
/*各种声明*/
int* binary(IplImage* img, int bithro); //二值化图像
int outlinefeature(IplImage* imglk, int feature[][50]);//计算图像的轮廓特征值
IplImage* Cjbsb(IplImage* img, IplImage* imgjbsb, int jbwhite, int jbblack);//图像角标识别
IplImage* singlefeature(char* path, int feature[][50]){
//定义变量
IplImage* img = 0; //原图
IplImage* imglk = 0; //轮廓图
IplImage* imggj = 0; //骨架图
IplImage* imgjbsb = 0; //角标识别图
IplImage* imgbj = 0; //只提取笔记部分的图像
IplImage* imgbjhf = 0; //为文字区域画上方格
IplImage* imgwzbj = 0; //为文字区域标出是否为文字(文字标记)
int height, width, step, channels;
uchar *data;
int i, j;
int *black; //用于返回图像每行黑像素的个数
//int feature[50][50]={0}; //特征值初始化
img = cvLoadImage(path, 0);
/* 获取图像信息*/
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
/*开始处理*/
/*图像放大*/
IplImage* imgbig = 0; //原图的放大图
CvSize dst_cvsize; //目标图像的大小
float scale = 1;
if (width<840){
scale = (float)840 / width;
dst_cvsize.width = 840;
dst_cvsize.height = (int)(height*scale);
}
else
{
dst_cvsize.width = width;
dst_cvsize.height = height;
}
imgbig = cvCreateImage(dst_cvsize, img->depth, img->nChannels);
cvResize(img, imgbig, CV_INTER_LINEAR); // CV_INTER_NN - 最近邻插值,
//CV_INTER_LINEAR - 双线性插值 (缺省使用),
//CV_INTER_AREA - 使用象素关系重采样。当图像缩小时候,该方法可以避免波纹出现。
//CV_INTER_CUBIC - 立方插值.
/*二值化*/
int bithro = 230; //输入二值化的阈值 (0--255)
black = binary(imgbig, bithro); //二值化,并统计黑像素的个数,返回每行黑像素的个数(black)
//cvNamedWindow("二值化结果图",CV_WINDOW_AUTOSIZE); //显示图像
//cvShowImage("二值化结果图",img);
//printf("二值化求解完成!!\n");
/*角标识别*/
int jbwhite = 5, jbblack = 4;
imgjbsb = cvCreateImage(cvGetSize(imgbig), imgbig->depth, imgbig->nChannels);
imgbj = Cjbsb(imgbig, imgjbsb, jbwhite, jbblack); //返回文字的笔迹部分
/*计算骨架图*/
imggj = cvCreateImage(cvGetSize(imgbj), imgbj->depth, imgbj->nChannels); //复制
cvCopy(imgbj, imggj, NULL);
uchar *gjdata = (uchar *)imggj->imageData;
beforethin(gjdata, gjdata, imggj->width, imggj->height);
for (j = 0; j<imggj->height; j++)
{ //取值范围转到0--1
for (i = 0; i<imggj->width; i++)
{
if (gjdata[j*imggj->widthStep + i] == 255)
gjdata[j*imggj->widthStep + i] = 1;
}
}
ThinnerRosenfeld(imggj->imageData, imggj->height, imggj->width);
for (j = 0; j<imggj->height; j++)
{//取值范围转到0--255,反转过来
for (i = 0; i<imggj->width; i++)
{
if (gjdata[j*imggj->widthStep + i] == 1)
gjdata[j*imggj->widthStep + i] = 0;
else
gjdata[j*imggj->widthStep + i] = 255;
}
}
//保存图像 应先生成图像文件名
/*
char processPic[100]="E:/imggj/";
char *namePic=new char[20];
bool flag=false;
string xuehao=path,kaoshihao=path;
int num_iter=sizeof(path);
for(int iter=0;iter<num_iter;iter++)
{
if(path[iter]=='x')
{
flag=true;
break;
}
}
if(flag)
{
xuehao=xuehao.substr(27,13);
kaoshihao=kaoshihao.substr(40,5);
}else
{
xuehao=xuehao.substr(27,12);
kaoshihao=kaoshihao.substr(39,5);
}
strcat(processPic,xuehao.c_str());
_mkdir(processPic);
strcat(processPic,kaoshihao.c_str());
strcat(processPic,".jpg");
cvSaveImage(processPic,imggj);
*/
/*计算骨架特征徝*/
outlinefeature(imggj, feature); //特征值占48*48的右上三角形feature调用返回
//cvWaitKey(0);
/*释放内存*/
cvReleaseImage(&imgbig);
cvReleaseImage(&img);
cvReleaseImage(&imgbj);
cvReleaseImage(&imglk);
cvReleaseImage(&imgjbsb);
cvReleaseImage(&imgbjhf);
cvReleaseImage(&imgwzbj);
cvDestroyAllWindows();
return imggj;
}