資源簡介
采用zinnia手寫識別引擎,掌握zinnia 引擎接口,使用Qt編譯zinnia的源代碼。
參考原帖:http://www.qtprogrammer.org/?p=43#more-43
代碼片段和文件信息
//
//??Zinnia:?Online?hand?recognition?system?with?machine?learning
//
//??$Id:?character.cpp?17?2009-04-05?11:40:32Z?taku-ku?$;
//
//??Copyright(C)?2008?Taku?Kudo?
//
#include?
#include?
#include?
#include?
#include?
#include?
#include?“common.h“
#include?“zinnia.h“
#include?“sexp.h“
#include?“scoped_ptr.h“
namespace?zinnia?{
class?CharacterImpl:?public?Character?{
?public:
??void?set_value(const?char?*str)?{
????value_.assign(str?std::strlen(str));
??}
??void?set_value(const?char?*str?size_t?length)?{
????value_.assign(str?length);
??}
??const?char?*value()?const?{
????return?value_.c_str();
??}
??void?set_width(size_t?width)?{
????width_?=?width;
??}
??void?set_height(size_t?height)?{
????height_?=?height;
??}
??size_t?width()?const?{?return?width_;?}
??size_t?height()?const?{?return?height_;?}
??void?clear()?{?strokes_.clear();?}
??bool?add(size_t?id?int?x?int?y);
??size_t?strokes_size()?const?{
????return?strokes_.size();
??}
??size_t?stroke_size(size_t?id)?const?{
????return?(strokes_.size()?<=?id)??
????????static_cast(-1)?:?strokes_[id].size();
??}
??int?x(size_t?id?size_t?i)?const?{
????return?(id?>=?strokes_.size()?||?i?>=?strokes_[id].size())??
????????-1?:?strokes_[id][i].x;
??}
??int?y(size_t?id?size_t?i)?const?{
????return?(id?>=?strokes_.size()?||?i?>=?strokes_[id].size())??
????????-1?:?strokes_[id][i].y;
??}
??bool?parse(const?char?*str?size_t?length);
??bool?parse(const?char?*str)?{
????return?parse(str?std::strlen(str));
??}
??bool?toString(char?*buf?size_t?length)?const;
??const?char?*what()?{?return?what_.str();?}
??CharacterImpl():?width_(300)?height_(300)?{}
??virtual?~CharacterImpl()?{?clear();?}
?private:
??struct?Dot?{
????int?x;
????int?y;
??};
??std::vector?>?strokes_;
??std::string?value_;
??size_t?width_;
??size_t?height_;
??whatlog?what_;
??scoped_ptr?sexp_;
};
bool?CharacterImpl::add(size_t?id?int?x?int?y)?{
??strokes_.resize(id?+?1);
??Dot?d;
??d.x?=?x;
??d.y?=?y;
??strokes_[id].push_back(d);
??return?true;
}
//?parse?S-expression
//?(character
//???(value?A)
//???(width?100)
//???(height?100)
//???(strokes?(?(0?1)?(1?2)?)?(?(0?1)?(1?2)?)?)?)
bool?CharacterImpl::parse(const?char?*str?size_t?length)?{
??clear();
??if?(!sexp_.get())?{
????sexp_.reset(new?Sexp);
??}
??sexp_->free();
??char?*begin?=?const_cast(str);
??const?char?*end?=?str?+?length;
??const?Sexp::Cell?*root_cell?=?sexp_->read(&begin?end);
??if?(!root_cell)?{
????sexp_->free();
????return?false;
??}
??const?Sexp::Cell?*ccel?=?root_cell->car();
??if?(!ccel->is_atom()?||?std::strcmp(“character“?ccel->atom())?!=?0)?{
????sexp_->free();
????return?false;
??}
??for?(const?Sexp::Cell?*it?=?root_cell->cdr();?it;?it?=?it->cdr())?{
????const?Sexp::Cell?*cell=?it->car();
????if?(cell->car()?&&?cell->car()->is_atom()?&&
????????cell->cdr()?&&?cell->cdr()->car()?&&
????????cell->cdr()->car()->is_atom())?{
??????const?char?*
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4891??2009-04-05?19:40??zinnia\character.cpp
?????文件??????48880??2011-03-10?17:09??zinnia\character.o
?????文件???????3420??2011-03-10?12:29??zinnia\common.h
?????文件???????3087??2011-02-23?09:56??zinnia\config.h
?????文件???????5103??2009-04-05?19:40??zinnia\feature.cpp
?????文件???????1382??2009-04-05?19:40??zinnia\feature.h
?????文件??????35456??2011-03-10?17:09??zinnia\feature.o
?????文件???????1464??2009-04-05?19:40??zinnia\freelist.h
?????文件???26834816??2009-06-22?08:27??zinnia\handwriting-zh_CN.model
?????文件??????11679??2009-04-05?19:40??zinnia\libzinnia.cpp
?????文件??????58904??2011-03-10?17:09??zinnia\libzinnia.o
?????文件????????441??2011-03-10?16:21??zinnia\main.cpp
?????文件???????7356??2011-03-10?17:09??zinnia\main.o
?????文件??????10869??2011-03-10?17:08??zinnia\Makefile
?????文件???????5012??2009-04-05?19:40??zinnia\mmap.h
?????文件???????2615??2011-03-10?17:09??zinnia\moc_QHWR.cpp
?????文件??????12076??2011-03-10?17:09??zinnia\moc_QHWR.o
?????文件???????5932??2009-04-05?19:40??zinnia\param.cpp
?????文件???????2387??2009-04-05?19:40??zinnia\param.h
?????文件??????40128??2011-03-10?17:09??zinnia\param.o
?????文件???????7112??2011-03-10?17:06??zinnia\QHWR.cpp
?????文件???????1732??2011-03-10?16:03??zinnia\QHWR.h
?????文件??????33848??2011-03-10?17:09??zinnia\QHWR.o
?????文件???????4921??2010-05-09?13:34??zinnia\recognizer.cpp
?????文件??????46892??2011-03-10?17:09??zinnia\recognizer.o
?????文件???????1830??2009-04-05?19:40??zinnia\scoped_ptr.h
?????文件???????3350??2009-04-05?19:40??zinnia\sexp.cpp
?????文件???????1978??2009-04-05?19:40??zinnia\sexp.h
?????文件???????7464??2011-03-10?17:09??zinnia\sexp.o
?????文件???????1398??2009-04-05?19:40??zinnia\stream_wrapper.h
............此處省略13個文件信息
評論
共有 條評論