void PLAYER::on_predicted_input(NETOBJ_PLAYER_INPUT *new_input)
{
	CHARACTER *chr = get_character();
	if(chr)
		chr->on_predicted_input(new_input);
}
Beispiel #2
0
	void	root::notify_key_event(player* player, key::code k, bool down)
	{
		// multithread plugins can call gameswf core therefore we should 
		// use gameswf mutex to lock gameswf engine
		gameswf_engine_mutex().lock();

		// First notify global Key object
		// listeners that uses the last keypressed code
		player->notify_key_object(k, down);

		// Notify keypress listeners.
		if (down)
		{
			m_keypress_listener.notify(event_id(event_id::KEY_PRESS, (key::code) k));
		}

		// A bit of a hack huh
		if( k == key::SHIFT )
		{
			m_shift_key_state = down;
		}

		if (((key::code)k == key::TAB) && down)
		{
			bool killfocus = false;
			int	 tab = 0;
			int  lastvalid = -1;

			// lets see if focus is in the root
			int i = 0;
			for (i = 0; get_character(i) != NULL; ++i)
			{
				character* movie = get_character(i);
				assert(movie);

				if (movie->is(AS_EDIT_TEXT) == false)
				{
					continue;
				}

				if (movie->can_handle_mouse_event() == false)
				{
					continue;
				}

				if (movie == m_current_active_entity.get_ptr())
				{
					if (lastvalid != -1 && m_shift_key_state)
					{
						movie->on_event(event_id::KILLFOCUS);
						get_character(lastvalid)->on_event(event_id::SETFOCUS);
						break;
					}
					//we only want to kill focus if there is another event below this one
					tab = i;

					//now i need to find which event to set focus on
					killfocus = true;
					continue;
				}

				lastvalid = i;

				if (killfocus)
				{
					get_character(tab)->on_event(event_id::KILLFOCUS);
					movie->on_event(event_id::SETFOCUS);
					killfocus = false;
					break;
				}
			}

			if (get_character(i) == NULL)
			{
				for (int i = 0; get_character(i) != NULL; ++i)
				{
					if (stricmp(get_character(i)->type_of(), "movieclip") != 0)
					{
						continue;
					}

					change_focus_character(get_character(i), m_current_active_entity.get_ptr(), m_shift_key_state);
				}
			}
		}

		gameswf_engine_mutex().unlock();
	}
//Some thoughts: we don't need all these character classes
//Some other thoughts: Understand how scan works in the
//context of the entire program.
void scan(location_t * loc, token_t * tok)
{
    //an enumeration of the different possible states
    //also initializes "state" to "start," which is 0
    enum {
            start,
            got_space,
            got_nl_space,
            got_other,
            done,
        /* numbers: */
            got_dot,
            got_dec,
            got_fp_dot,
        /* operators: */
            got_plus,
            got_minus,
            got_star,
            got_slash,
            got_pct,
            got_lparen,
            got_incr,
            got_decr,
            got_incr2,
            got_decr2,
            got_caret,
            got_bang
    } state = start;

/* Standard way to recognize a token: put back lookahead character that
    isn't part of current token: */
#define ACCEPT_REUSE(t) \
    *loc = loc_save;    \
    tok->length--;      \
    tok->tc = t;        \
    state = done;

#define ACCEPT_SHIFT(t, i)          \
    move_location_back(loc, i);    \
    tok->length = tok->length - i;  \
    tok->tc = t;                    \
    state = done;

/* Shortcut to eliminate final states with no out transitions: go
    ahead and accept token in previous state, but don't put back the
    lookahead: it's actually part of the token: */
#define ACCEPT(t) \
    tok->tc = t;  \
    state = done;

//NOTE: the following code is NOT part of the ACCEPT(t)
    tok->location = *loc;
    tok->length = 0;

    while (state != done) {
        //Points to loc -- but if we update loc, we update loc_save
        location_t loc_save = *loc;
        //Gets the character, but also updates loc by incrementing it
        int c = get_character(loc);
        //I guess... we might be adding this character to the token?
        tok->length++;
        //WAIT A SECOND -- THIS WHOLE SWITCH-CASE IS A DFA. :O
        switch (state) {
            //If we're in the start state...
            case start:
                //... find out which character class the character is in
                switch (char_classes[c]) {
                    case WHITE:
                        state = got_space;
                        break;
                    case EOLN:
                        state = got_nl_space;
                        break;
                    case DOT:
                        state = got_dot;
                        break;
                    case DIG:
                        state = got_dec;
                        break;
                    case PLUS:
                        state = got_plus;
                        break;
                    case MINUS:
                        state = got_minus;
                        break;
                    case STAR:
                        state = got_star;
                        break;
                    case PCT:
                        state = got_pct;
                        break;
                    case SLASH:
                        state = got_slash;
                        break;
                    case CARET:
                        state = got_caret;
                        break;
                    case BANG:
                        state = got_bang;
                        break;
                    case LPAREN:
                        state = got_lparen;
                        break;
                    case RPAREN:
                        tok->terminal = t_RPAREN;
                        ACCEPT(T_RPAREN);
                        break;
                    case SEMIC:
                        tok->terminal = t_SEMIC;
                        ACCEPT(T_SEMIC);
                        break;
                    case END:
                        ACCEPT_REUSE(T_EOF);
                        break;
                    case OTHER:
                        /* This will be an error.  Eat as many bogus
                            characters as possible. */
                        state = got_other;
                        break;
                    default:
                        state = got_other;
                        break;
                }
                break;
            case got_space:
                switch (char_classes[c]) {
                    case WHITE:
                        break;  /* stay put */
                    case EOLN:
                        state = got_nl_space;
                        break;
                    default:
                        ACCEPT_REUSE(T_SPACE);
                        break;
                }
                break;
            case got_nl_space:
                switch (char_classes[c]) {
                    case WHITE:
                    case EOLN:
                        break;  /* stay put */
                    default:
                        ACCEPT_REUSE(T_NL_SPACE);
                        break;
                }
                break;
            case got_other:
                switch (char_classes[c]) {
                    case OTHER:
                    case WHITE:
                    case EOLN:
                        break;  /* stay put */
                    default:
                        fprintf(stderr, "Invalid token");
                        print_location(tok);
                        ACCEPT_REUSE(T_SPACE);    /* most likely recovery? */
                        break;
                }
                break;
            //This, theoretically, should be unreachable -- state would have to change
            //outside of a switch statement, which, by current design is, dare I say,
            //impossible. But, this being a computer program prone to bugs, let's just
            //say "improbable."
            case done:
                fprintf(stderr, "scan: unexpected done in switch\n");
                exit(-1);
                break;

            /* operators: */
            //What about positive and negative? We want the scanner
            //to parse the positive and negative signs for me
            case got_plus:
                tok->terminal = t_PLUS;
                ACCEPT_REUSE(T_OPERATOR);       //  +
                break;
            case got_minus:
                tok->terminal = t_MINUS;
                ACCEPT_REUSE(T_OPERATOR);       //  -
                break;
            case got_star:
                tok->terminal = t_STAR;
                ACCEPT_REUSE(T_OPERATOR);       //  * 
                break;
            case got_slash:
                tok->terminal = t_SLASH;
                ACCEPT_REUSE(T_OPERATOR);       //  /
                break;
            case got_pct:
                tok->terminal = t_PCT;
                ACCEPT_REUSE(T_OPERATOR);       //  %
                break;
            case got_caret:
                tok->terminal = t_CARET;
                ACCEPT_REUSE(T_OPERATOR);
                break;
            case got_bang:
                tok->terminal = t_BANG;
                ACCEPT_REUSE(T_OPERATOR);
                break;
            case got_lparen:
                switch(char_classes[c]){
                    case PLUS:
                        state = got_incr;
                        break;
                    case MINUS:
                        state = got_decr;
                        break;
                    default:
                        tok->terminal = t_LPAREN;
                        ACCEPT_REUSE(T_LPAREN);
                        break;
                }
                break;
            case got_incr:
                switch(char_classes[c]){
                    case PLUS:
                        state = got_incr2;
                        break;
                    case RPAREN:
                        tok->terminal = t_PLUS_UNARY;
                        ACCEPT(T_UNARY);
                        break;
                    default:
                        tok->terminal = t_LPAREN;
                        ACCEPT_SHIFT(T_LPAREN, 2);
                        break;
                }
                break;
            case got_decr:
                switch(char_classes[c]){
                    case MINUS:
                        state = got_decr2;
                        break;
                    case RPAREN:
                        tok->terminal = t_MINUS_UNARY;
                        ACCEPT(T_UNARY);
                        break;
                    default:
                        tok->terminal = t_LPAREN;
                        ACCEPT_SHIFT(T_LPAREN, 2);
                        break;
                }
                break;
            case got_incr2:
                switch(char_classes[c]){
                    case RPAREN:
                        tok->terminal = t_INCREMENT;
                        ACCEPT(T_INCREMENT);
                        break;
                    default:
                        tok->terminal = t_LPAREN;
                        ACCEPT_SHIFT(T_LPAREN, 3);
                        break;
                }
                break;
            case got_decr2:
                switch(char_classes[c]){
                    case RPAREN:
                        tok->terminal = t_DECREMENT;
                        ACCEPT(T_INCREMENT);
                        break;
                    default:
                        tok->terminal = t_LPAREN;
                        ACCEPT_SHIFT(T_LPAREN, 3);
                        break;
                }
                break;
            /* numeric literals: */
            //We assume that a dot means that it's a decimal
            case got_dot:
                state = got_fp_dot;
                break;
            case got_dec:
                switch (char_classes[c]) {
                    case DIG:
                        break;  /* stay put */
                    case DOT:
                        state = got_fp_dot;
                        break;
                    /*case LET_E:
                        state = starting_exp;
                        break;*/
                    default:
                        tok->terminal = t_LITERAL;
                        ACCEPT_REUSE(T_LITERAL);  /* decimal integer */
                        break;
                }
                break;
            case got_fp_dot:
                switch (char_classes[c]) {
                    case DIG:
                        break;  /* stay put */
                    default:
                        tok->terminal = t_LITERAL;
                        ACCEPT_REUSE(T_LITERAL);  /* fp */
                        break;
                }
                break;
        }
    }
}
Beispiel #4
0
// Convenience function. Gets a character, pushes it.
void push_character(char stack[], int maxSize, int *currentSize) {
    char value = get_character();
    push(stack, maxSize, currentSize, value);
}
Beispiel #5
0
int advance(Dictionary dict) {
   /* this reads the next token from the input into token */
    wint_t c;
	int i, quote_mode;

    dict->is_special = FALSE;

    if (dict->already_got_it != L'\0') {
		dict->is_special = (wcschr(SPECIAL, dict->already_got_it) != NULL);
		
		if (dict->already_got_it == WEOF) {
			dict->token[0] = L'\0';
		} else {
			dict->token[0] = dict->already_got_it;
			dict->token[1] = L'\0';
		}
		
		dict->already_got_it = L'\0';
		return 1;
    }

    do c=get_character(dict, FALSE); while (iswspace(c));

    quote_mode = FALSE;

    i = 0;
    for (;;) {
	if (i > MAX_TOKEN_LENGTH-1) {
	    dict_error(dict, L"Token too long");
	    return 0;
	}
	if (quote_mode) {
	    if (c == L'\"') {
		quote_mode = FALSE;
		dict->token[i] = L'\0';
		return 1;
	    }
	    if (iswspace(c)) {
		dict_error(dict, L"White space inside of token");
		return 0;
	    }	     
	    dict->token[i] = c;
	    i++;
	} else {
	    if (wcschr(SPECIAL, c) != NULL) {
		if (i==0) {
		    dict->token[0] = c;
		    dict->token[1] = L'\0';
		    dict->is_special = TRUE;
		    return 1;
		}
		dict->token[i] = L'\0';
		dict->already_got_it = c;
		return 1;
	    }
	    if (c==WEOF) {
		if (i==0) {
		    dict->token[0] = L'\0';
		    return 1;
		}
		dict->token[i] = L'\0';
		dict->already_got_it = c;
		return 1;
	    }
	    if (iswspace(c)) {
		dict->token[i] = L'\0';
		return 1;
	    }
	    if (c == L'\"') {
		quote_mode = TRUE;
	    } else {
		dict->token[i] = c;
		i++;
	    }
	}
	c = get_character(dict, quote_mode);
    }
    return 1;
}
Beispiel #6
0
/**
 * This reads the next token from the input into token.
 * Return 1 if a character was read, else return 0 (and print a warning).
 */
static int link_advance(Dictionary dict)
{
	wchar_t c;
	int nr, i;
	int quote_mode;

	dict->is_special = FALSE;

	if (dict->already_got_it != '\0')
	{
		dict->is_special = is_special(dict->already_got_it, &dict->mbss);
		if (dict->already_got_it == WEOF) {
			dict->token[0] = '\0';
		} else {
			dict->token[0] = dict->already_got_it; /* specials are one byte */
			dict->token[1] = '\0';
		}
		dict->already_got_it = '\0';
		return 1;
	}

	do { c = get_character(dict, FALSE); } while (iswspace(c));

	quote_mode = FALSE;

	i = 0;
	for (;;)
	{
		if (i > MAX_TOKEN_LENGTH-3) {  /* 3 for multi-byte tokens */
			dict_error(dict, "Token too long");
			return 0;
		}
		if (quote_mode) {
			if (c == '\"') {
				quote_mode = FALSE;
				dict->token[i] = '\0';
				return 1;
			}
			if (iswspace(c)) {
				dict_error(dict, "White space inside of token");
				return 0;
			}

			/* Although we read wide chars, we store UTF8 internally, always. */
			nr = wcrtomb(&dict->token[i], c, &dict->mbss);
			if (nr < 0) {
#ifndef _WIN32
				dict_error2(dict, "Unable to read UTF8 string in current locale",
				         nl_langinfo(CODESET));
				fprintf (stderr, "\tTry setting the locale with \"export LANG=en_US.UTF-8\"\n");
#else
				dict_error(dict, "Unable to read UTF8 string in current locale");
#endif
				return 0;
			}
			i += nr;
		} else {
			if (is_special(c, &dict->mbss))
			{
				if (i == 0)
				{
					dict->token[0] = c;  /* special toks are one char always */
					dict->token[1] = '\0';
					dict->is_special = TRUE;
					return 1;
				}
				dict->token[i] = '\0';
				dict->already_got_it = c;
				return 1;
			}
			if (c == 0x0) {
				if (i == 0) {
					dict->token[0] = '\0';
					return 1;
				}
				dict->token[i] = '\0';
				dict->already_got_it = c;
				return 1;
			}
			if (iswspace(c)) {
				dict->token[i] = '\0';
				return 1;
			}
			if (c == '\"') {
				quote_mode = TRUE;
			} else {
				/* store UTF8 internally, always. */
				nr = wctomb_check(&dict->token[i], c, &dict->mbss);
				if (nr < 0) {
#ifndef _WIN32
					dict_error2(dict, "Unable to read UTF8 string in current locale",
					         nl_langinfo(CODESET));
					fprintf (stderr, "\tTry setting the locale with \"export LANG=en_US.UTF-8\"\n");
#else
					dict_error(dict, "Unable to read UTF8 string in current locale");
#endif
					return 0;
				}
				i += nr;
			}
		}
		c = get_character(dict, quote_mode);
	}
	return 1;
}
Beispiel #7
0
unsigned char* frame_receiver(){
	int roundNo,i,size;
	char ch;
	unsigned int* dataparity;
	unsigned char* data;
	unsigned char* datain = (unsigned char*)malloc(sizeof(unsigned char)*12);

	roundNo=12;
	printf("roundNo:%d\n",roundNo);

	printf("-----------\n");

	i=0;
	while(i<roundNo){
		printf("I : %d",i);
		ch=get_character();
		datain[i++]=ch;
		printf(">> %x\n",datain[i-1]);
	}
	puts("RECEIVED\n");

	size=IgetSize(datain);
	printf("I>S : %d\n ",IgetStart(datain));
	printf("I>C : %d\n ",IgetControl(datain));
	printf("I>F : %d\n ",IgetFrameno(datain));
	printf("I>Z : %d\n ",size);

	dataparity=Igetdata(datain);

	//printf("Parity Check %s\n", parityChecker(dataparity,size)); //parityChecker(dataparity,size)==1?"TRUE":"FALSE"

	data=(unsigned char*)malloc(sizeof(unsigned char)*IgetSize(datain));


	///////////// Parity Checker \\\\\\\\\\\\\\\\\\\\\

	i=0;
	while(i<size){
		data[i]=(dataparity[i])>>1;
		i++;
		//dataparity++;
	}

	i=0;
	while(i<size){
		printf("D: %c 0x%x\n",data[i],data[i]);
		//data++;
		i++;
	}

	// TEST
/*
	i=0;
	while(i<12){
		printf("D in Parity : %x \n",dataparity[i++]>>1);
		//i++;
		//dataparity++;
	}*/
	

	return data; // User strlen(data) to find it Size.
}
Beispiel #8
0
void md12_main(void) {
	switch (next_state) {
		
		case STATE_MENU:
			switch(create_dialog(MP3_MENU, DOT_1 | DOT_2 | ENTER_CANCEL)) {
				
				case NO_DOTS:
					break;

				case '1':
					PRINTF("[MD12] Submode: Learn\n\r");
					play_mp3(MODE_FILESET, MP3_INSTRUCTIONS);
					submode = SUBMODE_LEARN;
					next_state = STATE_GENQUES;
					break;

				case '2':
					PRINTF("[MD12] Submode: Play\n\r");
					play_mp3(MODE_FILESET, MP3_INSTRUCTIONS);
					submode = SUBMODE_PLAY;
					next_state = STATE_GENQUES;
					break;

				case CANCEL:
					PRINTF("[MD12] Quitting to main menu\n\r");
					quit_mode();
					break;

				case ENTER:
					PRINTF("[MD12] Re-issuing main menu prompt\n\r");
					next_state = STATE_MENU;
					break;

				default:
					break;			
			}
			break;

		case STATE_GENQUES:
			switch (submode) {

				case SUBMODE_LEARN:
					curr_glyph = get_next_glyph(SCRIPT_ADDRESS);
					if (curr_glyph == NULL) {
						reset_script_indices(SCRIPT_ADDRESS);
						next_state = STATE_GENQUES;
						break;
					}
					break;

				case SUBMODE_PLAY:
					curr_glyph = get_random_glyph(SCRIPT_ADDRESS);
					break;

				default:
					break;

			}
			sprintf(dbgstr, "[MD12] Next glyph: %s\n\r", curr_glyph->sound);
			PRINTF(dbgstr);
			play_mp3(LANG_FILESET, MP3_NEXT_LETTER);
			next_state = STATE_PROMPT;
			break;

		case STATE_PROMPT:
			switch(submode) {

				case SUBMODE_LEARN:
					play_glyph(curr_glyph);
					play_mp3(MODE_FILESET, MP3_FOR_X_PRESS_DOTS);
					play_dot_sequence(curr_glyph);
					break;

				case SUBMODE_PLAY:
					play_silence(500);
					play_glyph(curr_glyph);
					break;

				default:
					break;
			}
			next_state = STATE_INPUT;
			break;

		case STATE_INPUT:
			if (io_user_abort == true) {
				PRINTF("[MD12] User aborted input\n\r");
				next_state = STATE_REPROMPT;
				io_init();
			}
			if (get_character(&user_glyph) == true) {
				PRINTF("[MD12] Valid character received\n\r");
				next_state = STATE_CHECK;
				io_init();
			}
			break;

		case STATE_CHECK:
			if (glyph_equals(curr_glyph, user_glyph)) {
				incorrect_tries = 0;
				PRINTF("[MD12] User answered correctly\n\r");
				play_mp3(LANG_FILESET, MP3_CORRECT);
				play_mp3(SYS_FILESET, MP3_TADA);
				next_state = STATE_GENQUES;
			} else {
				incorrect_tries++;
				PRINTF("[MD12] User answered incorrectly\n\r");
				play_mp3(LANG_FILESET, MP3_INCORRECT);
				play_mp3(LANG_FILESET, MP3_TRY_AGAIN);
				next_state = STATE_PROMPT;
				if (incorrect_tries >= MAX_INCORRECT_TRIES) {
					play_glyph(curr_glyph);
					play_mp3(MODE_FILESET, MP3_FOR_X_PRESS_DOTS);
					play_dot_sequence(curr_glyph);
					play_mp3(LANG_FILESET, MP3_TRY_AGAIN);
					next_state = STATE_INPUT;
				}
			}
			break;

		case STATE_REPROMPT:
			switch(create_dialog(MP3_REPROMPT,
				DOT_1 | DOT_2 | DOT_3 | ENTER_CANCEL | LEFT_RIGHT)) {
				case NO_DOTS:
					break;

				case '1':
					PRINTF("[MD12] Skipping character\n\r");
					next_state = STATE_GENQUES;
					break;

				case '2':
					PRINTF("[MD12] Playing pattern\n\r");
					play_glyph(curr_glyph);
					play_mp3(MODE_FILESET, MP3_FOR_X_PRESS_DOTS);
					play_dot_sequence(curr_glyph);
					play_mp3(LANG_FILESET, MP3_TRY_AGAIN);
					next_state = STATE_INPUT;
					break;

				case '3':
					PRINTF("[MD12] Reissuing prompt\n\r");
					next_state = STATE_PROMPT;
					break;

				case CANCEL:
					PRINTF("[MD12] Cancelling to submode menu\n\r");
					md12_reset();
					break;

				case ENTER:
					PRINTF("[MD12] Reissuing prompt\n\r");
					next_state = STATE_PROMPT;
					break;

				case LEFT:
					PRINTF("[MD12] Previous letter\n\r");
					switch (submode) {
						case SUBMODE_LEARN:
							curr_glyph = get_prev_glyph(SCRIPT_ADDRESS);
							if (curr_glyph == NULL) {
								curr_glyph = get_next_glyph(SCRIPT_ADDRESS);
							}
							break;
						case SUBMODE_PLAY:
							curr_glyph = get_random_glyph(SCRIPT_ADDRESS);
							break;
						default:
							break;
					}
					play_glyph(curr_glyph);
					break;

				case RIGHT:
					PRINTF("[MD12] Next letter\n\r");
					switch (submode) {
						case SUBMODE_LEARN:
							curr_glyph = get_next_glyph(SCRIPT_ADDRESS);
							if (curr_glyph == NULL) {
								curr_glyph = get_prev_glyph(SCRIPT_ADDRESS);
							}
							break;
						case SUBMODE_PLAY:
							curr_glyph = get_random_glyph(SCRIPT_ADDRESS);
							break;
						default:
							break;
					}
					play_glyph(curr_glyph);
					break;

				default:
					break;
			}
			break;

		default:
			break;
	}
}
Beispiel #9
0
int main_plate(const char * car_name)
{
	
	/*********************************************准备工作*****************************************/
	IplImage * img_car = NULL;
	IplImage * img_car_after_resize = NULL;
	IplImage * img_after_preprocess = NULL;
	IplImage * img_plate = NULL;
	IplImage * img_after_resize = NULL;
	IplImage * img_character = NULL;

	List rects; /*保存预选车牌位置矩形的列表*/
	double scale = -1; /*在尺寸归一化时要用到*/
	int width = 0, height = 0; /*最开始时候的尺寸归一化的长宽*/
	int number = -1;	/*最后一个字符的数字结果*/
	int count_recog = 0;
	char filename[50];

#if 1
	//cvNamedWindow("img_car", 1);
//	cvNamedWindow("img_car_after_resize", 1);
	//cvNamedWindow("img_after_preprocess", 1);
	//cvNamedWindow("img_plate", 1);
#endif

	if ((img_car = cvLoadImage(car_name, -1)) == NULL) {
		fprintf(stderr, "Can not open car image file in main.c!\n");
		exit(-1);
	}

	/*****************************************开始进行图像处理***************************************/
	/*由于得到的车辆图像中车占的比例太小,所以需要考虑重新截取图像,保证得到的图像中车辆整体占整个图像的比例较大
	 要实现这个目的我们观察发现拍到的照片中车基本都是处于整个图像的中心,所以我们截取整个图像的中心作为新的图片
	 策略:
	 1.先将图片按宽度分成三份,取中间的一份,车牌肯定在这一份中
	 2.将图片上四分之一截取掉,下四分之一截取点,车牌肯定在剩下的二分之一份图片中
	 */
	/*********现在开始进行截取车身操作****************/
#if 0
	IplImage * tmp_img = cvCreateImage(cvSize(1.0 / 3 * img_car->width, 1.0 / 2 * img_car->height), img_car->depth, img_car->nChannels);
	cvSetImageROI(img_car, cvRect(1.0 / 3 * img_car->width, 1.0 / 4 * img_car->height, 1.0 / 3 * img_car->width, 1.0 / 2 * img_car->height));
	cvCopy(img_car, tmp_img);
	cvSaveImage("tmp_img.bmp", tmp_img);
	cvResetImageROI(img_car);
	img_car = cvLoadImage("tmp_img.bmp", -1);					/*img_car现在是新的截取后的图片了*/
	assert(img_car != NULL);

	cvNamedWindow("haha", 1);
	cvShowImage("haha", tmp_img);
	cvWaitKey(0);
#endif

	cut_image(img_car);
	img_car = cvLoadImage("image/tmp_img.bmp", -1);					/*img_car现在是新的截取后的图片了*/

	/********************************************************************************************************/
	/*为了便于对图像进行统一处理,先对图像尺寸进行处理,让图像的尺寸大小合适,
	  一般大概大小为640*480规格的,所以只需要大概按照这个比例进行resize
	 */



	/*用cvResize函数进行处理即可*/
#if 1
	scale = 1.0 * 640 / img_car->width;			/*将长度规整为640即可,宽就按比例伸长就行了*/
	width = scale * img_car->width;
	height = scale * img_car->height;
	img_car_after_resize = cvCreateImage(cvSize(width, height), img_car->depth, img_car->nChannels);
	cvResize(img_car, img_car_after_resize);			/*对尺寸进行归一化,得到宽为640的图像*/
	cvSaveImage("image/img_car_after_resize.bmp", img_car_after_resize);
#endif


	/*图像预处理:输入为尺寸归一化后的车牌图像,输出为一张img_after_preprocess.bmp图像*/
	preprocess_car_img(img_car_after_resize);

	/*读取img_after_preprocess.bmp图像*/
	if ((img_after_preprocess = cvLoadImage("image/img_after_preprocess.bmp", -1)) == NULL) {
		fprintf(stderr, "Can not open file img_after_preprocess.bmp in main.c");
		exit(-1);
	}

#if 1
	/*显示预处理完成后的图像*/
	//cvShowImage("img_car", img_after_preprocess);
	//cvShowImage("img_after_preprocess", img_after_preprocess);
#endif
	
	/***************************************预处理完成,开始找车牌位置*****************************************************************/
	rects = get_location(img_after_preprocess, img_car_after_resize);			/*得到车牌的位置,起初设计阶段是可以有多个预选位置,但是后来发现不用,所以rects其实只有一个位置,但是也是用一个链表装着的*/
	/*由于在get_location中返回的是头结点的next节点,所以这里的参数不用rects->next*/
	assert(count_node(rects) == 1);						/*断言这个链表里只有一个待选车牌位置*/
	/****************************************找到车牌位置,开始截取车牌******************************************************************/
	get_plate_image(img_car_after_resize, rects);		/*得到车牌的图像*/

	img_plate = cvLoadImage("image/plate_img0.bmp", -1);		/*上面那个函数中得到的plate_img.bmp图像*/
	if (img_plate == NULL) {
		fprintf(stderr, "Can not open plate image file!\n");
		exit(-1);
	}

	/*******************************************对车牌进行尺寸变化***************************************************************/
	scale = plate_resize_scale(img_plate);
	resize_image(img_plate,img_after_resize, scale);		/*最后一个参数为5表示将原车牌图像变长为原来的五倍*/
	if ((img_after_resize = cvLoadImage("image/plate_img_after_resize.bmp", -1)) == NULL) {
		fprintf(stderr, "Can not open file plate_img_after_resize.bmp in main.c");
		exit(-1);
	}

	/*******************************************对车牌进行预处理***************************************************************/
	preprocess_plate_image(img_after_resize);			/*对车牌图像进行预处理*/
	
	/********************************************获得车牌上的字符信息**************************************************************/
	get_character(img_after_resize);					/*得到每一个字符的图像*/
	//cvShowImage("image_car", img_after_resize);
	//printf("the plate is: \n");
	count_recog = 0;

    FILE *fp = fopen("result.txt", "wb");
    char buf[1] = {0};
    int ct = 0;
    while(ct++ < 10000) {
	fwrite(buf, 1, sizeof(char), fp);
    }
	fclose(fp);
	while (count_recog < 7) {

		sprintf(filename, "image/character%d.png", count_recog);

		img_character = cvLoadImage(filename, -1);

		if (img_character == NULL) {
			break;
		}

	/*********************************************开始进行字符识别***********************************************************/

		number = character_recognizing(img_character);
		count_recog++;
	}
	cvWaitKey(0);
	printf("Time used = %.2f\n", (double)clock() / CLOCKS_PER_SEC);
	return 0;
}