void Settings::setupGui() {
    ui.setupUi(this);

    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(saveSettings()));
    connect(ui.patternEdit, SIGNAL(textChanged(QString)), this, SLOT(changeAddPatternButtonState(QString)));

    connect(ui.patternAddButton, SIGNAL(clicked()), this, SLOT(addPattern()));
    connect(ui.patternDeleteButton, SIGNAL(clicked()), this, SLOT(deletePattern()));

    connect(ui.directoryOpenButton, SIGNAL(clicked()), this, SLOT(addDirectory()));
    connect(ui.directoryDeleteButton, SIGNAL(clicked()), this, SLOT(deleteDirectory()));
}
Example #2
0
/**
 * freeModels
 * Guess what
 **/
void
freeModels()
{
    int i, j;
    for ( i = 0; i < 3; i++ )
    {
	for ( j = 0; j < MAX_PATTERNS; j++ )
	    if ( models[i][j] != NULL )
		deletePattern( models[i][j] );
	if ( models[i] != NULL )
	    free( models[i] );
	models[i] = NULL;
    }
}
Example #3
0
/**
 * recognize
 * The magic! Given a pattern it returns the ascii that
 * it thinks is closest
 **/
unsigned char 
recognize( Pattern *p )
{
    unsigned char ascii;
    int mind, tmpd, i, nsamples;
    Pattern *np; 


    /**
     * Check for shift-symbol
     */
    if ( maxWidth( p ) < 6 )
	return '.';
    
    np = apply( preprocessor, p );
    calcSlopes( np );

    /*
     * Do the magic stuff
     */
    samples = models[ getBank() ];
    nsamples = npatterns[ getBank() ];
    unknown = np;
    ascii = samples[0]->ascii;
    mind = distance( 0 );

    for ( i = 1; i < nsamples; i++ )
    {
	tmpd = distance( i );
	if ( tmpd < mind )
	{
	    mind = tmpd;
	    ascii = samples[i]->ascii;
	}
    }
	
    /*
     * cleanup and return
     */
    deletePattern( np );
    return ascii;
}
Example #4
0
/**
 * loadPattern
 * Loads a pattern from file filename
 * The format of the file is the format used by Rob Kassel
 * in his PhD-thesis: A comparison of Approaches to On-line
 * Handwritten Character Recognition
 **/
Pattern *
loadPattern( char *filename )
{
    FILE *fp;
    Point po;
    int lineno = 0, readingStroke = 0, foundAscii = 0, tmp;
    char line[80], ascii = 0, *ptr;
    Pattern *p = newPattern( 30, 'a' ), *tp;

    if ( p == NULL )
	return NULL;

    fp = fopen( filename, "r" );
    if ( fp == NULL )
	return NULL;
    
    while ( fgets( line, 80, fp ) != NULL )
    {
	lineno++;
	if ( strstr( line, ".COMMENT" ) != NULL && 
	     strstr( line, "Prompt" ) != NULL )
	{
	    ptr = strchr( line, '"' );
	    if ( ptr == NULL )
	    {
		fprintf( stderr, "Parse error in %s on line %d\n",
			 filename, lineno );
		continue;
	    }

	    ascii = ptr[1];
	    if ( ascii == '#' )
	    {
		sscanf( ptr + 2, "%d", &tmp );
		ascii = (char) tmp;
	    }
	    foundAscii = 1;
	}

	if ( !readingStroke )
	{
	    if ( strstr( line, ".PEN_DOWN" ) )
		readingStroke = 1;
	}
	else
	{
	    if ( strlen( line ) > 0 && !isdigit( line[0] ) )
		readingStroke = 0;
	    
	    if ( strlen( line ) > 0 && isdigit( line[0] ) )
	    {
		if ( sscanf( line, "%d %d", &po.x, &po.y ) != 2 )
		{
		    fprintf( stderr, "Parse error in %s on line %d\n",
			     filename, lineno );
		    continue;
		}   
		po.y = 3058 - po.y;
		addPoint( p, po );
	    }
	}
    }
    fclose( fp );
    if ( !foundAscii || p->nPoints == 0 )
    {
	deletePattern( p );
	p = NULL;
    }
    else
    {
	tp = apply( preprocessor, p );
	deletePattern( p );
	p = tp;
    	p->ascii = (unsigned char) ascii;
	calcSlopes( p );
    }
    return p;
}