JNIEXPORT jstring JNICALL Java_com_sxc_homekeytestforndk_Zinnia_initData(JNIEnv* env, jclass thiz,jstring data)
{ 
	int len = (*env)->GetStringLength(env, data);
	char outbuf [len];
	(*env)->GetStringUTFRegion(env, data, 0, len, outbuf);
    zinnia_recognizer_t *recognizer = zinnia_recognizer_new();
    zinnia_character_t  *character  = zinnia_character_new();
    if (!zinnia_recognizer_open(recognizer, "/data/data/com.sxc.homekeytestforndk/files/test.model")) {
     return (*env)->NewStringUTF(env, "can not found the model file");
	}
	if (!zinnia_character_parse(character, outbuf)) {
    return (*env)->NewStringUTF(env, "can not parse");
  	}
  	
	zinnia_result_t *result = zinnia_recognizer_classify(recognizer, character, 10);
    size_t i; 
    if (!result) {
       return (*env)->NewStringUTF(env, "3error");
    }
    int length = zinnia_result_size(result);
	char buf[3*length];
	memset(buf, 0, 3*length);
    for (i = 0; i < length; ++i)
 	{
 	 	strcpy(&buf[3*i],zinnia_result_value(result,i));
    }
   // strcpy(&buf[0],zinnia_result_value(result,0));
   // strcpy(&buf[3],zinnia_result_value(result,1));
	zinnia_result_destroy(result);
	zinnia_character_destroy(character);
	zinnia_recognizer_destroy(recognizer);
    return (*env)->NewStringUTF(env,buf);
}
Exemple #2
0
int main(int argc, char **argv) {
  size_t i;
  zinnia_recognizer_t *recognizer;
  zinnia_character_t *character;
  zinnia_result_t *result;

  recognizer = zinnia_recognizer_new();

  if (!zinnia_recognizer_open(recognizer, "/usr/local/lib/zinnia/model/tomoe/handwriting-ja.model")) {
    fprintf(stderr, "ERROR: %s\n", zinnia_recognizer_strerror(recognizer));
    return -1;
  }

  zinnia_character_t  *character  = zinnia_character_new();
  zinnia_character_clear(character);
  zinnia_character_set_width(character, 300);
  zinnia_character_set_height(character, 300);
  zinnia_character_add(character, 0, 51, 29);
  zinnia_character_add(character, 0, 117, 41);
  zinnia_character_add(character, 1, 99, 65);
  zinnia_character_add(character, 1, 219, 77);
  zinnia_character_add(character, 2, 27, 131);
  zinnia_character_add(character, 2, 261, 131);
  zinnia_character_add(character, 3, 129, 17);
  zinnia_character_add(character, 3, 57, 203);
  zinnia_character_add(character, 4, 111, 71);
  zinnia_character_add(character, 4, 219, 173);
  zinnia_character_add(character, 5, 81, 161);
  zinnia_character_add(character, 5, 93, 281);
  zinnia_character_add(character, 6, 99, 167);
  zinnia_character_add(character, 6, 207, 167);
  zinnia_character_add(character, 6, 189, 245);
  zinnia_character_add(character, 7, 99, 227);
  zinnia_character_add(character, 7, 189, 227);
  zinnia_character_add(character, 8, 111, 257);
  zinnia_character_add(character, 8, 189, 245);

  result = zinnia_recognizer_classify(recognizer, character, 10);
  if (result == NULL) {
    fprintf(stderr, "%s\n", zinnia_recognizer_strerror(recognizer));
    return -1;
  }


  for (i = 0; i < zinnia_result_size(result); ++i) {
    fprintf(stdout, "%s\t%f\n",
            zinnia_result_value(result, i),
            zinnia_result_score(result, i));
  }

  zinnia_result_destroy(result);
  zinnia_character_destroy(character);
  zinnia_recognizer_destroy(recognizer);

  return 0;
}
Exemple #3
0
void* ZinniaCreate(FcitxTabletConfig* cfg) {
	Zinnia* zn = fcitx_utils_new(Zinnia);
	zn->recog = zinnia_recognizer_new();
	// create the engine
	if (!zinnia_recognizer_open(zn->recog, cfg->ZinniaModel)) {
		FcitxLog(ERROR, "Could not create Zinnia engine: %s", zinnia_recognizer_strerror(zn->recog));
		return NULL;
	}
	zn->result = NULL;
	// The output string. 30 chars should be plenty.
	zn->candidates = (char*) malloc(30 * sizeof(char));
	return zn;
}
static int zinnia_open_model(IbusHandwriteRecogZinnia*obj)
{
	const char * tlang="zh_CN";

	g_debug(("using zinnia!!!"));
#ifdef WITH_ZINNIA
	tlang = lang;
#endif

	gchar * file = g_strdup_printf("%s/handwriting-%s.model",TOMOE_DATA_DIR,tlang);
	if (!zinnia_recognizer_open(obj->recognizer, file))
	{
		fprintf(stderr,  "ERROR: %s\n", zinnia_recognizer_strerror(
				obj->recognizer));
		g_free(file);
		return -1;
	}
	g_free(file);
	return 0;
}
/*
 * Class:     com_key_handwrite_Zinnia
 * Method:    zinnia_recognizer_open
 * Signature: (JLjava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_com_key_handwrite_Zinnia_zinnia_1recognizer_1open
  (JNIEnv *env, jobject jobj, jlong recognizer, jstring filename)
{
    zinnia_recognizer_t* p = reinterpret_cast<zinnia_recognizer_t*>(recognizer);
    return zinnia_recognizer_open(p, env->GetStringUTFChars(filename, NULL));
}
Exemple #6
0
QHWR::QHWR(QWidget* parent):QWidget(parent),allpage(0),index(0)
{
    recognizer= zinnia_recognizer_new();                           //注册引擎
    if (!zinnia_recognizer_open(recognizer,"handwriting-zh_CN.model")) {
        std::cerr << zinnia_recognizer_strerror(recognizer) << std::endl;
        return;
    }

    recogtimer.setInterval(1000);
    recogtimer.stop();
    connect(&recogtimer,SIGNAL(timeout()),this,SLOT(recognize()));


    LButtons[0]=new QPushButton(this);
    LButtons[0]->setGeometry(0,250,20,20);
    connect(LButtons[0],SIGNAL(clicked()),this,SLOT(chooseQchar()));

    LButtons[1]=new QPushButton(this);
    LButtons[1]->setGeometry(25,250,20,20);
    connect(LButtons[1],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[2]=new QPushButton(this);
    LButtons[2]->setGeometry(50,250,20,20);
    connect(LButtons[2],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[3]=new QPushButton(this);
    LButtons[3]->setGeometry(75,250,20,20);
    connect(LButtons[3],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[4]=new QPushButton(this);
    LButtons[4]->setGeometry(100,250,20,20);
    connect(LButtons[4],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[5]=new QPushButton(this);
    LButtons[5]->setGeometry(125,250,20,20);
    connect(LButtons[5],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[6]=new QPushButton(this);
    LButtons[6]->setGeometry(150,250,20,20);
    connect(LButtons[6],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[7]=new QPushButton(this);
    LButtons[7]->setGeometry(175,250,20,20);
    connect(LButtons[7],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[8]=new QPushButton(this);
    LButtons[8]->setGeometry(200,250,20,20);
    connect(LButtons[8],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    LButtons[9]=new QPushButton(this);
    LButtons[9]->setGeometry(225,250,20,20);
    connect(LButtons[9],SIGNAL(clicked()),this,SLOT(chooseQchar()));


    up=new QPushButton(tr("上"),this);
    up->setGeometry(250,250,20,20);
    connect(up,SIGNAL(clicked()),this,SLOT(turnpageup()));

    down=new QPushButton(tr("下"),this);
    connect(down,SIGNAL(clicked()),this,SLOT(turnpagedown()));
    down->setGeometry(275,250,20,20);
    genbuttonstate();
}
/*============================================================================*/
ChandWriter::ChandWriter( Cdialog *parent, const Crect &rect, const std::string &model, int distance)
: Cimage( parent, rect, KEY_NONE, "", BORDER_NONE, 0, "")
, m_stroke(0)
, m_distance(1000)
, m_started(false)
, m_lastPoint(0,0)
, m_recognizer( NULL)
, m_character( NULL)
, m_result( NULL)
, m_minimum_distance(distance)
{
	//int options =SDL_SWSURFACE; //|SDL_NOFRAME;
	//options =SDL_SWSURFACE|SDL_NOFRAME;
    //Uint32 rmask, gmask, bmask, amask;

    //m_backgroundColour =Cgraphics::m_defaults.handwriting_background;
    m_background.setColours( Cgraphics::m_defaults.handwriting_background, Cgraphics::m_defaults.handwriting_background);
    /* SDL interprets each pixel as a 32-bit number, so our masks must depend
       on the endianness (byte order) of the machine */
	#if 0 //SDL_BYTEORDER ==SDL_BIG_ENDIAN
		rmask = 0xff000000;
		gmask = 0x00ff0000;
		bmask = 0x0000ff00;
		amask = 0x000000ff;
	#else
		//bmask = 0x000000ff;
		//gmask = 0x0000ff00;
		//rmask = 0x00ff0000;
		//amask = 0; //0xff000000;
	#endif

	if ( Cgraphics::m_defaults.handwriting_detection_enabled)
	{
#ifdef USE_SDL2
		assert(0);
		//m_surface =SDL_CreateTexture( m_graphics->m_renderer,
		//		                      SDL_PIXELFORMAT_ARGB8888,
		//							  SDL_TEXTUREACCESS_TARGET,
		//							  m_rect.width()*8, m_rect.height()*8);
#else
		m_surface =SDL_CreateRGBSurface( options, m_rect.width()*8, m_rect.height()*8,
										 ::m_mainGraph->bitsPerPixel(),
										 rmask, gmask, bmask, amask);
#endif
#ifdef USE_ZINNIA
		m_recognizer = zinnia_recognizer_new();

		if (!zinnia_recognizer_open( m_recognizer, model.c_str()))
		{
		    //"ChandWriter::ChandWriter  ERROR: %s\n", zinnia_recognizer_strerror( m_recognizer));
			return;
		}

		  m_character  = zinnia_character_new();
#endif
	 }
	 //zinnia_character_clear( m_character);
	 //zinnia_character_set_width( m_character, m_rect.width());
	 //zinnia_character_set_height( m_character, m_rect.height());
	 clearImage();
	 enablePainting(); //enableDrag();
}
handwritor::handwritor (int * ret, char * err, QWidget * focus,
	const char * model, QWidget * parent)
	: QWidget(parent), allpage(0), index(0) {
	int i, open_result;
	char errstr[HANDWRITOR_ERR_MIN];
	QSpacerItem * spacer;
	QPalette palette;
	QFont font;

	this->destroyed = false;

	this->writor_layout = NULL;
	this->option_layout = NULL;
	this->candidate_layout = NULL;

	this->recognizer = NULL;
	this->recognizer = zinnia_recognizer_new();/* create recognizer engine */
	/* open model */
	if (model) {
		open_result = zinnia_recognizer_open(this->recognizer, model);
	} else {
		open_result = zinnia_recognizer_open(this->recognizer,
			HANDWRITOR_MODEL_DFT);
	}
	if (! open_result) {
		memset(errstr, 0, HANDWRITOR_ERR_MIN);
		strncpy(errstr, zinnia_recognizer_strerror(this->recognizer),
			HANDWRITOR_ERR_MIN - 1);
		if (err) {
			strncpy(err, errstr, HANDWRITOR_ERR_MIN - 1);
		}
		if (ret) {
			*ret = -1;/* zinnia_recognizer_open fail */
		}
		std::cerr << errstr << std::endl;
		goto fail_return;
	} /* ! open_result */

	/* ready to recognize */
	recogtimer.setInterval(1000);
	recogtimer.stop();
	QObject::connect(&recogtimer, SIGNAL(timeout()), this, SLOT(recognize()));

	/* writor */
	this->setContentsMargins(0, 0, 0, 0);
	this->setFixedSize(writor_width_fixed, writor_height_fixed);
	this->setAutoFillBackground(true);
	palette.setColor(QPalette::Background, QColor(0xff, 0xff, 0xff));
	this->setPalette(palette);

	master_layout= new QVBoxLayout(this);

	this->writor_layout = new QHBoxLayout();
	this->writor_layout->setContentsMargins(0, 0, 0, 0);

	spacer = new QSpacerItem(handwritor::writor_width_fixed - 64 - 10,
		handwritor::writor_height_fixed - 64 - 10);
	this->writor_layout->addItem(spacer);

	this->option_layout = new QVBoxLayout();
	this->option_layout->setContentsMargins(0, 0, 0, 0);

	spacer = new QSpacerItem(36, 24);
	this->option_layout->addItem(spacer);

	this->up = new QPushButton(tr("<<"), this);
	this->up->setFixedSize(36, 36);
	font.setPixelSize(14);
	this->up->setFont(font);
	this->up->setStyleSheet(__STLST_AL);
	this->option_layout->addWidget(this->up);

	spacer = new QSpacerItem(36, 24);
	this->option_layout->addItem(spacer);

	this->down = new QPushButton(tr(">>"), this);
	this->down->setFixedSize(36, 36);
	this->down->setFont(font);
	this->down->setStyleSheet(__STLST_AL);
	this->option_layout->addWidget(this->down);

	spacer = new QSpacerItem(36, 24);
	this->option_layout->addItem(spacer);

	this->option_layout->setAlignment(this->up,
		Qt::AlignRight | Qt::AlignVCenter);
	this->option_layout->setAlignment(this->down,
		Qt::AlignRight | Qt::AlignVCenter);
	this->option_layout->setStretch(0, 1);
	this->option_layout->setStretch(1, 1);
	this->option_layout->setStretch(2, 1);
	this->option_layout->setStretch(3, 1);
	this->option_layout->setStretch(4, 1);

	/*
	this->option_layout->setStretch(0, 7);
	this->option_layout->setStretch(1, 1);
	*/

	this->candidate_layout = new QHBoxLayout();
	this->candidate_layout->setContentsMargins(5, 0, 5, 0);
	/* ready candidate_btns */
	for (i = 0; i < 10; ++i) {
		candidate_btns[i] = new QPushButton(this);
		candidate_btns[i]->setFixedSize(36, 36);
		candidate_btns[i]->setFont(font);
		candidate_btns[i]->setStyleSheet(__STLST_AL);
		this->candidate_layout->addWidget(candidate_btns[i]);
	}

	this->writor_layout->addLayout(this->option_layout);
	this->writor_layout->setAlignment(this->option_layout, Qt::AlignCenter);

	master_layout->addLayout(this->writor_layout, 0);
	master_layout->addLayout(this->candidate_layout, 1);

	for (i = 0; i < 10; ++i) {
		this->candidate_layout->setAlignment(candidate_btns[i],
			Qt::AlignHCenter);
	}

	for (i = 0; i < 10; ++i) {
		QObject::connect(candidate_btns[i], SIGNAL(clicked()), this,
		SLOT(chooseQchar()));
	}
	QObject::connect(up, SIGNAL(clicked()), this, SLOT(turnpageup()));
	QObject::connect(down, SIGNAL(clicked()), this, SLOT(turnpagedown()));

	this->genbuttonstate();

	return;

fail_return:
	this->destroy();

} /* handwritor::handwritor */