Exemplo n.º 1
0
int count_node(BINNODE root)
{
	if(root!=NULL)
		return 1 + count_node(root->left) + count_node(root->right);
	else
		return 0;
}
Exemplo n.º 2
0
Arquivo: tree_c.c Projeto: cjack/Adt4c
int count_node(tree *root){
	if(root != NULL){
		return 1 + count_node(left) + count_node(right);
	}else{
		retrun 0;
	}
}
int count_node(pnode ps)
{
    if (ps != NULL)
    {
        count_n++;
        count_node(ps->lchild);
        count_node(ps->rchild);
    }
    return count_n;
}
void main()  
{  
    pnode ps;  
    ps=create_tree();  
      
    printf("pre order.../n");  
    print_pretree(ps);  
    printf("/n");  
    printf("mid order.../n");  
    print_midtree(ps);  
    printf("/n");  
    printf("post order.../n");  
    print_posttree(ps);  
    printf("/n");  
    printf("number of leaf is: %d/n", count_leaf(ps));  
    printf("number of node is: %d/n", count_node(ps));  
    printf("max  of  depth is: %d/n", count_depth(ps));  
}  
Exemplo n.º 5
0
int _list () {
	node* head = NULL;
//	node* head2 = NULL;
	int i = 0;// 'A';
	//int count = 0;
	while (i<10)
		append_node(&head,i++);
i--;
	while (i>=0)
		append_node(&head,i--);

#if 0
	insert_node(&head,11);
	insert_node(&head,0);
	insert_node(&head,100);
#endif
	print_node(head);
    //even_odd_merge(head);
	list_mirror (head);
    //reverse_sublist (&head, 5, 6);
	print_node(head);
	printf ("Total # of node is %d\n",count_node(head));
//	print_node(head2);
//	printf ("Total # of node is %d\n",count_node(head2));
//    node* result = merge_lists(head, head2);
//	print_node(result);
//	printf ("Total # of node is %d\n",count_node(result));
	// print_nth_node_from_last_rec(head,3,count);
	// prepend_node(&head,i++);
	// prepend_node(&head,i);
	// head = reverse_list(head);
	// reverse_list(&head);
	// print_node(head);
	// print_nth_node_from_last_rec(head,3,count);
	// printf ("Total # of node is %d\n",count_node(head));
	// printf ("loop %s detected\n",detect_loop (head)? "is":"is not");
	// delete_node(&head,i);
	// printf ("Total # of node is %d\n",count_node(head));
	// delete_node_by_addr(head);
	// printf ("5th node from last is %d\n",print_nth_node_from_last (head,5));
	// print_node(head);
	// printf ("Total # of node is %d\n",count_node(head));
	return 0;
}
Exemplo n.º 6
0
void menu()
{
	int c=0,data;
	BINNODE temp;
	while(c!=9)
	{
	printf("\t\t\t\tMenu for AVL tree build and Traversal\n");
	printf("\t\t\t1.Insert into AVL tree\n");
	printf("\t\t\t2.Search in AVL tree\n");
	printf("\t\t\t3.Height of the tree\n");
	printf("\t\t\t4.Number of nodes in the tree\n");
	printf("\t\t\t5.Inorder Traversal\n");
	printf("\t\t\t9.Exit\n");
		printf("\t\t\t\tEnter your choice:");
	scanf("%d",&c);
		switch(c)
		{
			case 1:
			printf("Enter the data to be inserted:");
			scanf("%d",&data);
			if(root==NULL)
			{
			if((temp=(BINNODE)malloc(sizeof(struct binnode)))\
			==NULL)
				printf("Error 1:\
				Memory Allocation Problem.\n");
			else
				{
				temp->data=data;
				temp->left=NULL;
				temp->right=NULL;
				temp->balance_factor=0;
				root=temp;
				}
			}
			else
				insert_node(data);
			break;
			case 2:
			printf("Enter the data to serach:");
			scanf("%d",&data);
			if((temp=search_node(root,data))==NULL)
				printf("Node does not exist.\n");
			else
				printf("Node found,with balance factor:%d\n"
				,temp->balance_factor);
			break;
			case 3:
				printf("Height of the tree:%d\n"\
				,tree_height(root));
			break;
			case 4:
				printf("Number of nodes in the tree:%d\n"\
				,count_node(root));
				break;
			case 5:
				print_inorder(root);
				printf("\n");
				break;
			case 9:
				deallocate(root);
				printf("Exiting...\n");
				break;


		}
	}
Exemplo n.º 7
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;
}