int main(int argc, char *argv[]) { int count = atoi(argv[1]); link temp = NULL; link new_node = NULL; link head = (node*)malloc(sizeof(node)); head->next = NULL; head->item = -1; temp = head; for (int loop = 0; loop < count; ++loop) { new_node = add_node(loop); temp->next = new_node; temp = temp->next; } link reversed_link = reverse_link(head); release_link(reversed_link); return 0; }
int main() { /*读配置文件*/ FILE* fp; char readin[100],file[100]; int value1=0, value2=0, value3=0,value4=0,value5=0; fopen_s(&fp, "configure/configure.txt", "r"); fscanf_s(fp, "video: %s", readin, sizeof(readin)); sprintf(file, readin); memset(readin, 0, sizeof(readin)); fgets(readin, sizeof(readin),fp); fscanf_s(fp, "value1: %d", &value1, sizeof(int)); memset(readin, 0, sizeof(readin)); fgets(readin, sizeof(readin), fp); fscanf_s(fp, "value2: %d", &value2, sizeof(int)); memset(readin, 0, sizeof(readin)); fgets(readin, sizeof(readin), fp);; fscanf_s(fp, "value3: %d", &value3, sizeof(int)); memset(readin, 0, sizeof(readin)); fgets(readin, sizeof(readin), fp); fscanf_s(fp, "value4: %d", &value4, sizeof(int)); memset(readin, 0, sizeof(readin)); fgets(readin, sizeof(readin), fp); fscanf_s(fp, "value5: %d", &value5, sizeof(int)); printf("%s %d %d %d\n", file,value1,value2,value3); /*声明IplImage指针*/ IplImage *image0 = NULL; //原始帧 IplImage *image = NULL; //当前帧 IplImage *image_pass = NULL; //上一帧 IplImage *res = NULL; //帧差 IplImage *res0 = NULL; //帧差 IplImage *pFrame = NULL; IplImage *pFrImg = NULL; IplImage *pBkImg = NULL; /*声明CvMat指针*/ CvMat* pFrameMat = NULL; CvMat* pFrMat = NULL; CvMat* pBkMat = NULL; CvMat* IndexMat = NULL; /*声明caputer指针*/ CvCapture *capture = NULL; capture = cvCaptureFromFile(file); image0 = cvQueryFrame(capture); nFrmNum++; // 创建窗口 //cvNamedWindow("video", 1); cvNamedWindow("background", 1); cvNamedWindow("tracking", 1); // 排列窗口 //cvMoveWindow("video", 30, 80); cvMoveWindow("background",10, 100); cvMoveWindow("tracking", 660, 100); /*移动物体的队列*/ movingObject *curr_head = new movingObject(); movingObject *prev_head = new movingObject(); movingObject *p_obj = new movingObject(); movingObject *share_head = new movingObject(); curr_head->next = NULL; curr_head->share_next = NULL; prev_head->next = NULL; prev_head->share_next = NULL; share_head->next = NULL; CvScalar color[7] = { { 0, 0, 0 }, { 0, 255, 0 }, {255, 0, 0 }, { 255, 201, 14 }, { 255, 0, 255 }, { 0, 166, 0 }, {121,255,121} }; image = cvCreateImage(cvSize(640,360), IPL_DEPTH_8U, 3); cvResize(image0, image, CV_INTER_LINEAR); int image_width = image->width; int image_height = image->height; image_pass = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3); res = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1); res0 = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 3); pBkImg = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1); pFrImg = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1); pFrame = cvCreateImage(cvSize(image_width, image_height), IPL_DEPTH_8U, 1); pBkMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1); pFrMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1); pFrameMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1); IndexMat = cvCreateMat(image_height, image_width, CV_32FC1); cvCopy(image, image_pass, NULL); /*背景*/ cvCvtColor(image, pBkImg, CV_BGR2GRAY); cvConvert(pBkImg, pBkMat); while (1) { image0 = cvQueryFrame(capture); if (!image0) break; cvResize(image0, image, CV_INTER_LINEAR); /*高斯平滑*/ cvSmooth(image, image, CV_GAUSSIAN, 3, 0, 0); /*运动目标检测*/ detect_object(image, pBkImg, pFrImg, pFrameMat, pBkMat, pFrMat,value1); /*帧差法优化*/ frame_dif(image, image_pass, res,res0, pFrImg,pFrame,value2); cvConvert(pFrame, pFrMat); /*计算连通区域和质心*/ computeObject(pFrMat, image_width, image_height,IndexMat, curr_head,value3); /*画出质心*/ p_obj = curr_head; while (p_obj->next != NULL) { p_obj = p_obj->next; cvRectangle(image, cvPoint(p_obj->x - 1, p_obj->y - 1), cvPoint(p_obj->x + 1, p_obj->y + 1), cvScalar(0, 0, 255), 2, 8, 0); } if (nFrmNum == 2) { movingObject* q = NULL; computeObject(pFrMat, image_width, image_height, IndexMat, prev_head,value3); } /*画出跟踪框*/ if (nFrmNum > 2) { movingObject *q = NULL, *p = NULL; movingObject *last=curr_head; for (q = curr_head->next; q; ) { int close = 0; share_head->share_next = NULL; for (p = prev_head->next; p; p = p->next) { int dist = cal_dist(p->x, p->y, q->x, q->y); if (dist <= value5) { close++; p->share_next = share_head->share_next; share_head->share_next= p; } } if (close == 1) { if (share_head->share_next->track == 1) //已被用,删掉当前结点 { last->next = q->next; movingObject* t=q; q = q->next; delete t; continue; } q->label = (share_head->share_next)->label; cvRectangle(image, q->points[0], q->points[1], color[q->label],2); q->move = q->x - (share_head->share_next)->x; //两帧位移 share_head->share_next->track = 1; q->track = 0; q->keeptime = 0; last = q; q = q->next; } else if (close==0) { //生成新标签 q->label = ++label_num; cvRectangle(image, q->points[0], q->points[1], color[q->label],2); q->track = 0; q->keeptime = 0; last = q; q = q->next; } else if (close>1) { movingObject* t = share_head->share_next; while ( t != NULL) { if (t->track==1) t = t->share_next; else break; } if (t==NULL) //全部跟踪完毕 { last->next = q->next; t = q; q = q->next; delete t; continue; } //重用当前队列的这一object q->label = t->label; q->move = t->move; q->area = t->area; q->x = t->x + t->move; q->y = t->y; q->points[0].x = t->points[0].x+t->move; q->points[0].y = t->points[0].y; q->points[1].x = t->points[1].x + t->move; q->points[1].y = t->points[1].y; q->track = 0; t->track = 1; q->keeptime = 0; cvRectangle(image, q->points[0], q->points[1], color[q->label],2); t = t->share_next; while (t) { if (t->track == 1) { t = t->share_next; continue; } movingObject* newobject = new movingObject(); newobject->area = t->area; newobject->label = t->label; newobject->move = t->move; newobject->next = q->next; q->next = newobject; q = newobject; newobject->points[0].x = t->points[0].x + t->move; newobject->points[0].y = t->points[0].y; newobject->points[1].x = t->points[1].x + t->move; newobject->points[1].y = t->points[1].y; newobject->x = t->x + t->move; newobject->y = t->y; newobject->track = 0; newobject->keeptime = 0; cvRectangle(image, newobject->points[0], newobject->points[1], color[newobject->label],2); t->track = 1; //已跟踪这一个prev目标 t = t->share_next; } last = q; q = q->next; } }//end for detect_hiding(prev_head, image_width, curr_head,value4); }//end if cvShowImage("tracking", image); release_link(prev_head,share_head); prev_head->next = curr_head->next; curr_head->next = NULL; int ctrl; if ( (ctrl=cvWaitKey(20)) == 27)//ESC退出 { break; } else if (ctrl == 32) //空格暂停 { while ((ctrl=cvWaitKey(0))!=13)//回车继续 { if (ctrl == 27) exit(0); continue; } } } cvReleaseImage(&res); cvReleaseImage(&res0); cvReleaseImage(&image_pass); cvReleaseImage(&pBkImg); cvReleaseImage(&pFrImg); cvReleaseImage(&pFrame); cvReleaseCapture(&capture); return 1; }
//--------- Begin of function Firm::deinit --------// // void Firm::deinit() { if( !firm_recno ) // already deleted return; if( power.command_firm_recno == firm_recno ) power.reset_command(); // ##### begin Gilbert 30/10 ######// // mem_del(firm_cur_frame); // firm_cur_frame = NULL; // mem_del(firm_remain_frame_delay); // firm_remain_frame_delay = NULL; // ##### end Gilbert 30/10 ######// is_being_deleted = 1; // whether the place is currently being deleted, if it is set to true, some functions will be executed in an exceptional way, it is set in deinit() Place::deinit(); // parent class deinit() deinit_derived(); //------- delete AI info ----------// if( nation_recno ) { Nation* nationPtr = nation_array[nation_recno]; nationPtr->del_firm_info(firm_id, firm_recno); if(is_ai) { if( should_close_flag ) nationPtr->firm_should_close_array[firm_id-1]--; err_when( nationPtr->firm_should_close_array[firm_id-1] < 0 ); } } //--------- clean up related stuff -----------// restore_world_matrix(); release_link(); //-------- dynamic unloading of firm bitmaps ---------// FirmBuild* firmBuild = firm_res.get_build(firm_build_id); firmBuild->free_bitmap_res(); //------ all workers and the overseer resign ------// if( !sys.signal_exit_flag ) { // char* name1 = "Wilde Lishorr"; // char* name2 = "Lishorr"; // if( !under_construction && hit_points < 1 && strcmp(name1, firm_name()) && strcmp(name2, firm_name()) ) if( !under_construction && hit_points < 1 ) { // -------- create a firm die record ------// // can be called as soon as restore_world_matrix static int effectId = sprite_res.search_sprite( "FIRE_EFF" ); err_when( !effectId ); Effect::create(effectId, loc_x1 *LOCATE_WIDTH, loc_y1 *LOCATE_HEIGHT, SPRITE_IDLE, 1, 8, 0); FirmDie firmDie3; if (firmBuild->loc_width == 3 && firmBuild->loc_height == 3) firmDie3.init(this, 6); else if (firmBuild->loc_width == 6 && firmBuild->loc_height == 6) firmDie3.init(this, 5); else firmDie3.init(this, 4); firm_die_array.add(&firmDie3); } } free_all_people(); //--------- decrease firm counter -----------// if( nation_recno ) nation_array[nation_recno]->nation_firm_count--; //------ update firm counter -------// FirmInfo* firmInfo = firm_res[firm_id]; firmInfo->total_firm_count--; if( nation_recno ) firmInfo->dec_nation_firm_count(nation_recno); //------- update town border ---------// loc_x1 = -1; // mark deleted //------- if the current firm is the selected -----// if( firm_array.selected_recno == firm_recno ) { firm_array.selected_recno = 0; info.disp(); } //-------------------------------------------------// firm_recno = 0; is_being_deleted = 0; //-------- dynamic unloading of firm bitmaps ---------// // FirmBuild* firmBuild = firm_res.get_build(firm_build_id); if( firm_id ) { // firmBuild->free_bitmap_res(); firm_id = 0; } }
//------- Begin of function Firm::change_nation ---------// // void Firm::change_nation(int newNationRecno) { if( nation_recno == newNationRecno ) return; //---------- stop all attack actions to this firm ----------// unit_array.stop_attack_obj(base_obj_recno); rebel_array.stop_attack_firm(firm_recno); Nation *oldNationPtr = NULL; Nation *newNationPtr = NULL; if( nation_recno ) oldNationPtr = nation_array[nation_recno]; if( newNationRecno ) newNationPtr = nation_array[newNationRecno]; //------ if there is a builder in this firm, change its nation also ----// if( builder_recno ) { Unit* unitPtr = unit_array[builder_recno]; unitPtr->change_nation(newNationRecno); //--- if this is a spy, chance its cloak ----// if( unitPtr->spy_recno ) spy_array[unitPtr->spy_recno]->cloaked_nation_recno = newNationRecno; } //---------- stop all actions attacking this firm --------// unit_array.stop_attack_obj(base_obj_recno); //---- update nation_unit_count_array[] ----// FirmInfo* firmInfo = firm_res[firm_id]; if( nation_recno ) firmInfo->dec_nation_firm_count(nation_recno); if( newNationRecno ) firmInfo->inc_nation_firm_count(newNationRecno); //---- reset should_close_flag -----// if( is_ai ) { if( should_close_flag ) { if( oldNationPtr ) { oldNationPtr->firm_should_close_array[firm_id-1]--; err_when( oldNationPtr->firm_should_close_array[firm_id-1] < 0 ); } should_close_flag = 0; } } //------- update player_spy_count -------// spy_array.update_firm_spy_count(firm_recno); //--- update the cloaked_nation_recno of all spies in the firm ---// spy_array.change_cloaked_nation(SPY_FIRM, firm_recno, nation_recno, newNationRecno); // check the cloaked nation recno of all spies in the firm //-----------------------------------------// if( oldNationPtr ) oldNationPtr->del_firm_info(firm_id, firm_recno); //------ update power nation recno ----------// if( should_set_power ) world.restore_power(loc_x1, loc_y1, loc_x2, loc_y2, 0, firm_recno); should_set_power = get_should_set_power(); if( should_set_power ) world.set_power(loc_x1, loc_y1, loc_x2, loc_y2, newNationRecno); // set power of the new nation //------------ update link --------------// release_link(); // need to update link because firms are only linked to firms of the same nation nation_recno = newNationRecno; setup_link(); //---------------------------------------// if (!newNationRecno) is_ai = 1; else { is_ai = nation_array[nation_recno]->is_ai(); newNationPtr->add_firm_info(firm_id, firm_recno); } //--- if a nation set up a town in a location that the player has explored, contact between the nation and the player is established ---// establish_contact_with_player(); //---- reset the action mode of all spies in this town ----// spy_array.set_action_mode( SPY_FIRM, firm_recno, SPY_IDLE ); // we need to reset it. e.g. when we have captured an enemy town, SPY_SOW_DISSENT action must be reset to SPY_IDLE //-- refresh display if this firm is currently selected --// if( firm_array.selected_recno == firm_recno ) info.disp(); // ####### begin Gilbert 5/7 ########// if( explore_for_player() ) { world.unveil( loc_x1, loc_y1, loc_x2, loc_y2 ); world.visit( loc_x1, loc_y1, loc_x2, loc_y2, EXPLORE_RANGE-1 ); } // ####### end Gilbert 5/7 ########// }