static void InitPrintCut(void) { HWND Window,Mid; int xw,yw,i,j; char p[40]; int SaveColor; struct viewporttype SaveViewPort; BEGINOK; //WaitMessageEmpty(); MouseHidden(); getviewsettings(&SaveViewPort); SaveColor=getcolor(); SetPrinter(-CurrentPrinter); Window=PrintCutWin[wDISPWIN]; Mid=WindowGetFather(Window); ScreenDispWidth=WindowGetWidth(Window)-10; ScreenDispHeight=WindowGetHeight(Window)-10; WinX=ScreenX=WindowGetLeft(Window)+WindowGetLeft(Mid); WinY=ScreenY=WindowGetTop(Window)+WindowGetTop(Mid); setviewport(WinX,WinY,WinX+ScreenDispWidth+9,WinY+ScreenDispHeight+9,1); setwritemode(COPY_PUT); setcolor(EGA_WHITE); //setcolor(11); bar(0,0,ScreenDispWidth+9,ScreenDispHeight+9); PaperW=(float)(printer->xpixel)*25.4/PrinterDPI; PaperH=(float)(printer->ypixel)*25.4/PrinterDPI; SCRscaleX=PaperW/ScreenDispWidth; SCRscaleY=PaperH/ScreenDispHeight; if (SCRscaleX>SCRscaleY) SCRscaleY=SCRscaleX; else SCRscaleX=SCRscaleY; xw=mXw=PaperW/SCRscaleX; yw=mYw=PaperH/SCRscaleY; ScreenX=ScreenX+5+(ScreenDispWidth-mXw)/2; ScreenY=ScreenY+5+(ScreenDispHeight-mYw)/2; //setwritemode(COPY_PUT); setcolor(EGA_DARKGRAY); //gray setviewport(0,0,getmaxx(),getmaxy(),1); rectangle(ScreenX-1,ScreenY-1,ScreenX+xw,ScreenY+yw); //setviewport(ScreenX-1,ScreenY-1,ScreenX+xw,ScreenY+yw,1); //rectangle(ScreenX-1,ScreenY-1,ScreenX+xw,ScreenY+yw); //setviewport(ScreenX,ScreenY,ScreenX+mXw-1,ScreenY+mYw-1,1); GetUserFrame(0,&xw,&yw); PageWI=xw; PageHI=yw; PageW=xw*25.4/1000; PageH=yw*25.4/1000; sprintf(p,"%4d",(int)(PaperW+.5)); GetXY(3,&i,&j); DispXY(i-10,j,p,COLORP); sprintf(p,"%4d",(int)(PaperH+.5)); GetXY(4,&i,&j); DispXY(i-10,j,p,COLORP); setwritemode(COPY_PUT); setcolor(SaveColor); setviewport(SaveViewPort.left,SaveViewPort.top,SaveViewPort.right, SaveViewPort.bottom,SaveViewPort.clip); MouseShow(); }
bool SpatialAverageSpotter::train(string dirPath) { int count=0; vector<vector<tuple<int,Point2f> > > features; featureAverages.resize(codebook->size()); for (int i =0; i<codebook->size(); i++) featureAverages[i]=Mat(BASE_SIZE,BASE_SIZE,CV_32F,Scalar(0)); DIR *dir; struct dirent *ent; if ((dir = opendir (dirPath.c_str())) != NULL) { /* print all the files and directories within directory */ // Mat img; while ((ent = readdir (dir)) != NULL) { string fileName(ent->d_name); // cout << "examining " << fileName << endl; if (fileName[0] == '.' || fileName[fileName.size()-1]!='G') continue; Mat img = imread(dirPath+fileName, CV_LOAD_IMAGE_GRAYSCALE); // resize(img,img,Size(0,0),2,2); threshold(img,img,120.0,255,THRESH_BINARY); // windowWidth += img.cols; // windowHeight += img.rows; // int avg=0; // for (int x=0; x<img.cols; x++) // for (int y=0; y<img.rows; y++) // avg += (int)img.at<unsigned char>(y,x); //// cout << "avg="<<avg<<"/"<<img.cols*img.rows<<" = "<<avg/(img.cols*img.rows)<<endl; // avg /= img.cols*img.rows; resize(img,img,Size(PRE_BASE_SIZE,PRE_BASE_SIZE*((0.0+img.rows)/img.cols))); copyMakeBorder( img, img, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_CONSTANT, 255 ); assert(img.cols > 1 && img.rows > 1); adjustedTrainingImages.push_back(img.clone()); Point2f centerOfMass = findCenterOfMass(img); int offsetx=(img.cols/2)-centerOfMass.x; int offsety=(img.rows/2)-centerOfMass.y; translateImg(img,offsetx,offsety); vector<KeyPoint> keypoints; Mat desc; detectKeypoints( img,keypoints, desc); Mat out; cvtColor(img,out,CV_GRAY2RGB); circle(out,centerOfMass,1,Scalar(0,0,255)); features.resize(count+1); //double scaling = BASE_SIZE/img for (int r=0; r<desc.rows; r++) { int f = codebook->quantize(desc.row(r)); Point2f offsetPoint(keypoints[r].pt.x - centerOfMass.x, keypoints[r].pt.y - centerOfMass.y); features[count].push_back(make_tuple(f,offsetPoint));//we're ignoring the keypoint scale.. // circle(out,keypoints[r].pt,keypoints[r].size,Scalar(colorTable[f])); Rect rec(keypoints[r].pt.x-(keypoints[r].size/2),keypoints[r].pt.y-(keypoints[r].size/2),keypoints[r].size,keypoints[r].size); rectangle(out,rec,Scalar(colorTable[f])); } guassColorIn(features[count]); imshow("learning keypoints",out); cout << "image "<<count<<endl; waitKey(5); count++; // img.release(); } closedir (dir); } else { /* could not open directory */ perror (""); return false; } //We now step through adjusting the scales of the various images so the guass coloring is maximized //But we may still want to look at tfidf to see which ones should be weighted more, etc. maximizeAlignment(features); float max=0; float min =99999; float avg_max=0; int firstx=9999; int lastx=0; int firsty=9999; int lasty=0; for (int f=0; f<codebook->size(); f++) { float local_max=0; bool hitFirst=false; for (int x=0; x<featureAverages[f].cols; x++) for (int y=0; y<featureAverages[f].rows; y++) { float val = featureAverages[f].at<float>(y,x); if (val > 300 || val < -300) cout << "val (" << x <<","<<y<<") " << val << endl; if (val>max) max=val; if (val<min) min=val; if (val>local_max) local_max=val; if (val>WINDOW_THRESH) { if (!hitFirst) { hitFirst=true; if (x<firstx) firstx=x; if (y<firsty) firsty=y; } if (x>lastx) lastx=x; if (y>lasty) lasty=y; } } avg_max+=local_max; } // penalty=min+(max-min)*.2; avg_max /= codebook->size(); penalty=avg_max*.15;//.2 // windowWidth/=count; // windowHeight/=count; windowWidth = lastx-firstx; windowHeight = lasty-firsty; cout << "window size is "<<windowWidth<<"x"<<windowHeight<<endl; //show averages showAverages(); return true; }
void population::draw(QPainter *painter, float GLscale, float viewX, float viewY, int width, int height, QImage image, drawStyle style) { float scale = GLscale/200.0; this->setupTrans(GLscale, viewX, viewY, width, height); if (this->isSpikeSource) { style = spikeSourceDrawStyle; } switch (style) { case microcircuitDrawStyle: { // draw circle QPen oldPen = painter->pen(); QPen pen = painter->pen(); pen.setWidthF((pen.widthF()+1.0)*2*scale); painter->setPen(pen); painter->drawEllipse(transformPoint(QPointF(this->x, this->y)),0.5*GLscale/2.0,0.5*GLscale/2.0); painter->setPen(oldPen); QFont oldFont = painter->font(); QFont font = painter->font(); font.setPointSizeF(GLscale/10.0); painter->setFont(font); // print label QStringList text = this->name.split(" "); if (text.size()>0) { QString title = text.at(0); if (title.size() > 5) title.resize(5); painter->drawText(QRectF(transformPoint(QPointF(this->x-0.5, this->y-0.2)),transformPoint(QPointF(this->x+0.5, this->y+0.2))), Qt::AlignCenter, title); painter->setFont(oldFont); } return; } case layersDrawStyle: { return; } case spikeSourceDrawStyle: { // draw circle QPen oldPen = painter->pen(); QPen pen = painter->pen(); pen.setWidthF((pen.widthF()+1.0));//*GLscale/100.0 pen.setColor(QColor(200,200,200,0)); painter->setPen(pen); QBrush brush; brush.setStyle(Qt::SolidPattern); QColor col(this->colour); col.setAlpha(100); brush.setColor(col); QBrush oldBrush = painter->brush(); painter->setBrush(brush); painter->drawEllipse(transformPoint(QPointF(this->x, this->y)),0.5*GLscale/2.0,0.5*GLscale/2.0); QFont oldFont = painter->font(); QFont font = painter->font(); font.setPointSizeF(GLscale/10.0); painter->setFont(font); // print label pen.setColor(QColor(0,0,0,255)); painter->setPen(pen); //painter->drawText(QRectF(transformPoint(QPointF(this->x-0.5, this->y-0.2)),transformPoint(QPointF(this->x+0.5, this->y+0.2))), Qt::AlignCenter, "SS"); painter->setFont(oldFont); painter->setBrush(oldBrush); painter->setPen(oldPen); QImage ssimage(":/images/ssBig.png"); QRectF imRect(transformPoint(QPointF(this->x, this->y))-QPointF(0.4*GLscale/2.0,0.4*GLscale/2.0),QSizeF(0.4*GLscale,0.4*GLscale)); painter->drawImage(imRect, ssimage); return; break; } case standardDrawStyle: case standardDrawStyleExcitatory: case saveNetworkImageDrawStyle: default: // do nothing here, break out into the code below. break; } // transform the co-ordinates manually (using the qt transformation leads to blurry fonts!) float left = ((this->left+viewX)*GLscale+float(width))/2; float right = ((this->right+viewX)*GLscale+float(width))/2; float top = ((-this->top+viewY)*GLscale+float(height))/2; float bottom = ((-this->bottom+viewY)*GLscale+float(height))/2; QRectF rectangle(left, top, right-left, bottom-top); QRectF rectangleInner(left+2*scale, top+2*scale, right-left-8*scale, bottom-top-4*scale); QColor col(this->colour); col.setAlpha(100); QPainterPath path; path.addRoundedRect(rectangle,0.05*GLscale,0.05*GLscale); painter->fillPath(path, col); painter->drawImage(rectangle, image); // Draw a dark grey border around the population painter->setPen(QColor(200,200,200,255)); painter->drawRoundedRect(rectangle,0.05*GLscale,0.05*GLscale); painter->setPen(QColor(0,0,0,255)); QString displayed_name = this->name; if (displayed_name.size() > 13) { displayed_name.resize(10); displayed_name = displayed_name + "..."; } QString displayed_comp_name = this->neuronType->component->name; if (displayed_comp_name.size() > 14) { displayed_comp_name.resize(11); displayed_comp_name = displayed_comp_name + "..."; } QFont oldFont = painter->font(); QFont font = painter->font(); QString text = displayed_name + "\n" + QString::number(this->numNeurons);// + "\n" + displayed_comp_name; font.setPointSizeF(1.5*GLscale/20.0); painter->setFont(font); painter->drawText(rectangleInner, Qt::AlignRight|Qt::AlignTop, text); font.setPointSizeF(1.3*GLscale/20.0); painter->setFont(font); painter->setPen(QColor(60,60,60,255)); painter->drawText(rectangleInner, Qt::AlignRight|Qt::AlignBottom, displayed_comp_name); painter->setFont(oldFont); }
main() { int mode=VGAHI,driver=VGA; char ch; unsigned int l; int i,gi,gj,j,flag=1;/*i,j是循环变量,flag是标记变量,-1:向x负半轴移动,+1:向x正半轴移动*/ double qx,qy,k,b=0.0,speech=0.4,x,y; double r=2.0,bx=60.0,byy=270.0; double pianx=100.0,piany=100.0,tx=20.0,ty=10.0,jx=2.0,jy=2.0; int mx=0,my=0,mb,sum;/*sum纪录砖块的数目*/ FILE * p; if((p = fopen("record.dat", "r")) == NULL) { p=fopen("record.dat","w"); fprintf(p,"0 0 0 0 0\n"); rewind(p); } fclose(p); initgraph(&driver,&mode,"C:\\tc"); setbkcolor(BLUE); Msinit(); Setmouse((int)(pianx+1+bx/2),(int)((tx+jx)*8+pianx-1-bx/2),(int)byy+piany,(int)byy+piany); star: cleardevice();/*程序重载的介入点*/ setcolor(RED); outtextxy(30,20,"^_^ Welcome to Play Hitting Brick Game! ^_^"); sum=0; qx=100.0+pianx-10;qy=180.0+pianx-10;k=0.33; setcolor(7); rectangle((int)(pianx-2),(int)(piany-2),(int)((tx+jx)*8+2+pianx),302+piany); setcolor(1); rectangle((int)(pianx-1),(int)(piany-1),(int)((tx+jx)*8+1+pianx),301+piany); /*读取盘面情况*/ p=fopen("record.dat", "r"); for(i=0;i<5;i++) fscanf(p,"%x ",&zhuan[i]); fclose(p); /*画砖块*/ for(i=0;i<5;i++) { l=1; for(j=0;j<16;j++) { if((zhuan[i]&l)==0) { Draw((int)((jx+tx)*((16*i+j)%8)+pianx+jx),(int)((jy+ty)*((int)((16*i+j)/8))+piany+jy),(int)tx,(int)ty); sum+=1; } l=l*2; } } gotoxy(5,4); printf("Press any key to start game...Q key to quit..."); ch=getch(); if(ch=='q'||ch=='Q') quitgame(); else { gotoxy(5,4); printf(" "); } for(;;) { setfillstyle(1, 0); bar(mx-bx/2,my,mx+bx/2,my+5); Msread(&mx, &my, &mb); Draw(mx-bx/2,my,bx,5); setcolor(0); mycircle(qx,qy,r,0); /*判断求是否反弹*/ if(qx-r<=pianx+1 || qx+r>=(tx+jx)*8+pianx-1) { flag=-flag; k=-k; } if(qy-r<=piany+1) k=-k; for(gi=0;gi<5;gi++) { l=1; for(gj=0;gj<16;gj++) { if((zhuan[gi]&l)==0) { j=(16*gi+gj)/8; i=(16*gi+gj)%8; x=(jx+tx)*i+jx+tx/2+pianx; y=(jy+ty)*j+jy+ty/2+piany; /*边判断1*/ if(qy>=y-ty/2 && qy<=y+ty/2 &&(pow(qx+r-x+tx/2,2)<1 || pow(qx-r-x-tx/2,2)<1)) { flag=-flag; k=-k; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) wingame(); setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)*j+piany+jy+ty); } else /*边判断2*/ if(qx>=x-tx/2 && qx<=x+tx/2 &&(pow(qy+r-y+ty/2,2)<1 || pow(qy-r-y-ty/2,2)<1)) { k=-k; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) wingame(); setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)*j+piany+jy+ty); } else /*角判断*/ if(pow(qx-x+tx/2,2)+pow(qy-y+ty/2,2)<=r*r || pow(qx-x-tx/2,2)+pow(qy-y+ty/2,2)<=r*r || pow(qx-x+tx/2,2)+pow(qy-y-ty/2,2)<=r*r || pow(qx-x-tx/2,2)+pow(qy-y-ty/2,2)<=r*r) { flag=-flag; zhuan[gi]=zhuan[gi]|l; sum-=1; if(sum==0) wingame(); setfillstyle(1, 0); bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)*j+piany+jy+ty); } } l=l*2; } } /*棍棒的反弹*/ if(qx<=mx+bx/2 && qx>=mx-bx/2 && pow(qy+r-my,2)<1) { k=-(k/pow(k*k,0.5))*(0.3*bx/(pow(pow(qx-mx,2),0.5)+0.000001)); } if((int)(qy+r)>my+0.5) { gotoxy(5,5); printf("You have lost the game!Press any key to restart..."); getch(); goto star; } b=qy-qx*k; if(flag==1) qx=qx+speech/pow(1.0+k*k,0.5); if(flag==-1) qx=qx-speech/pow(1.0+k*k,0.5); qy=qx*k+b;/*计算球心坐标*/ setcolor(14); mycircle((int)qx,(int)qy,r,14); delay(1); if(mb==1) { gotoxy(5,5); printf("You have lost the game!Press any key to restart..."); getch(); goto star; } } }
void Camera::draw_box( Mat* img, Rect rect ){ rectangle(*img, Point(roi.x, roi.y), Point(roi.x+roi.width,roi.y+roi.height), Scalar(255,0,0), 2, 8, 0 ); }
void man(int a[1000][1000]) { int j=0; int i=0; int k=0; int l=0; int z=0; int c=1; int d=0; //initwindow(1000, 1000, "First Sample"); /*setcolor(WHITE); for(int i=1000;i>0;i--,j++) {rectangle(i, i,j, j); }*/ int xleft=150; int ytop=150; int xright=160; int ybottom=160; for(l=0;l<20;l++) {for(k=0;k<21;k++) { if(a[l][k]==0) setcolor(BLACK); else if(a[l][k]==1) setcolor(WHITE); else; for(i=0,j=0;i<10;i++,j--) {rectangle(i+xleft, i+ytop,j+xright, j+ybottom); } xleft+=10; xright+=10; } ytop+=10; ybottom+=10; xleft-=210; xright-=210; } setcolor(BLUE); //setcolor(GREEN); setbkcolor(WHITE); int test; outtextxy(120,155,"IN ->"); outtextxy(365,325,"-> OUT"); settextstyle(TRIPLEX_FONT,HORIZ_DIR,1); outtextxy(200,100,"LEVEL 1"); xleft=150; ytop=160; xright=160; ybottom=170; setcolor(YELLOW); for(i=0,j=0;i<10;i++,j--) {rectangle(i+xleft,i+ytop,j+xright,j+ybottom); setcolor(RED); } while(1) {if(!(c==18&&d==20)) {test=getch(); if(test==87||test==119) { if(a[c-1][d]==1) {setcolor(WHITE); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*(d))+i,150+(10*c)+i,160+(10*(d))-j,160+(10*c)-j); } c--; setcolor(YELLOW); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*d)+i,150+(10*c)+i,160+(10*d)-j,160+(10*c)-j); setcolor(RED); } } else cout<<"\a"; outtextxy(500,500,"UP");} else if(test==65||test==97) {outtextxy(500,500,"LEFT"); if(a[c][d-1]==1) {setcolor(WHITE); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*(d))+i,150+(10*c)+i,160+(10*(d))-j,160+(10*c)-j); } d--; setcolor(YELLOW); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*d)+i,150+(10*c)+i,160+(10*d)-j,160+(10*c)-j); setcolor(RED); } } else cout<<"\a"; } else if(test==83||test==115) { if(a[c+1][d]==1) {setcolor(WHITE); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*(d))+i,150+(10*c)+i,160+(10*(d))-j,160+(10*c)-j); } c++; setcolor(YELLOW); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*d)+i,150+(10*c)+i,160+(10*d)-j,160+(10*c)-j); setcolor(RED); } } else cout<<"\a"; outtextxy(500,500,"DO"); } else if(test==68||test==100) { if(a[c][d+1]==1) {setcolor(WHITE); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*(d))+i,150+(10*c)+i,160+(10*(d))-j,160+(10*c)-j); } d++; setcolor(YELLOW); for(i=0,j=0;i<5;i++,j++) {rectangle(150+(10*d)+i,150+(10*c)+i,160+(10*d)-j,160+(10*c)-j); setcolor(RED); } } else cout<<"\a"; outtextxy(500,500,"RI"); } else outtextxy(500,500,"IN"); } else {setcolor(RED); outtextxy(500,500,"YOU WON"); setcolor(GREEN); for(int xa=0;xa<50;xa++) circle(450,450,50-xa); setcolor(YELLOW); for(int xa=0;xa<50;xa++) circle(450,650,50-xa); setcolor(BLUE); for(int xa=0;xa<50;xa++) circle(450,550,50-xa);} } while (!kbhit( )) { delay(200); } while (kbhit( )) { delay(200); } //return 0; }
int main() { int gd=DETECT,gm,i=0,x,y,area; initgraph(&gd,&gm,"tc:\bgi");//put your directory contains egavga.bgi rectangle(0,0,getmaxx(),getmaxy());//to find max x and y coordinate in the screen arc(240,120,40,140,70);//arc(x,y,stangle,endangle,radius); ellipse(165,80,10,280,20,20);//ellipse (x,y,stangle,endangle,xrad,yrad) ,ears ellipse(315,80,-100,170,20,20);//ears arc(235,120,163,215,70); arc(245,120,-35,17,70); ellipse(193,178,85,280,40,20); ellipse(283,178,-100,95,40,20); ellipse(238,199,180,0,39,50); ellipse(213,123,44,240,33,40); ellipse(262,123,-60,135,33,40); ellipse(210,123,0,360,13,20);//left eye ellipse(265,123,0,360,13,20);//right eye ellipse(210,133,0,360,10,10);//left eye ball ellipse(265,133,0,360,10,10);//right eye ball ellipse(210,133,0,360,3,3);//left eye ball ellipse(265,133,0,360,3,3);//right eye ball ellipse(238,160,0,360,10,13);//nose arc(240,125,228,312,68);//mouth arc(240,120,230,310,72);//mouth setfillstyle(1,4); floodfill(238,100,15);//floodfill(238,160,15);//nose setfillstyle(1,15); floodfill(210,113,15); floodfill(265,113,15); setfillstyle(1,9); floodfill(210,100,15); setfillstyle(1,1); floodfill(315,80,15); moveto(203,220); lineto(203,260); lineto(183,260); lineto(183,350); lineto(293,350); lineto(293,260); lineto(273,260); lineto(273,220); moveto(183,350); lineto(173,460); lineto(213,460); lineto(238,400); lineto(263,460); lineto(303,460); lineto(293,350); moveto(173,460); lineto(143,478); lineto(213,478); lineto(213,460); moveto(263,460); lineto(263,478); lineto(333,478); lineto(303,460); line(238,400,238,350); //right hand moveto(183,260); lineto(113,310); lineto(183,375); moveto(183,280); lineto(137,310); lineto(181,353); setfillstyle(2,13); floodfill(190,300,15); setfillstyle(1,5); floodfill(223,400,15); setfillstyle(1,5); floodfill(253,400,15); setfillstyle(1,6); floodfill(173,470,15); floodfill(303,470,15); //fingers secondleft(); ellipse(413.5,228,0,180,3.5,3.5); line(420,240,433,240); line(423,247,440,247); line(413,240,410,228); line(417,228,420,240); ellipse(433,243.5,-90,90,3.5,3.5); line(423,254,440,254); ellipse(440,250.5,-90,90,3.5,3.5); ellipse(430,257,-90,90,3,3); line(413,260,430,260); area=imagesize(409,224,444,261); buf=malloc(area); getimage(409,224,444,261,buf); while(!kbhit()) { if(i==0) { setfillstyle(1,15); setcolor(15); ellipse(210,133,0,360,10,10);//left eye ball ellipse(265,133,0,360,10,10);//right eye ball setcolor(0); ellipse(210,133,0,360,3,3);//left eye ball ellipse(265,133,0,360,3,3);//right eye ball floodfill(210,133,15); floodfill(265,133,15); setcolor(0); putimage(391,209,buf,1); firstleft(); setcolor(15); secondleft(); putimage(409,224,buf,0); i=1; } else { setfillstyle(1,0); setcolor(0); ellipse(210,133,0,360,10,10);//left eye ball ellipse(265,133,0,360,10,10);//right eye ball floodfill(210,133,0); floodfill(265,133,0); setcolor(15); ellipse(210,133,0,360,3,3);//left eye ball ellipse(265,133,0,360,3,3);//right eye ball floodfill(210,133,15); floodfill(265,133,15); setcolor(0); putimage(409,224,buf,1); secondleft(); setcolor(15); firstleft(); putimage(391,209,buf,0); i=0; } delay(300); } getch(); return 0; }
void filemenu(int mode) { getstats(mode); if (button(100,100,170,120,"OPTIMIZE",9,13,base2,false,mode)==DDgui_LeftClick && mode!=DD_AfterCheck) { optimizeproject(); waitleftbutton=true; } if (button(100,121,170,141,"TextureO",9,13,base2,false,mode)==DDgui_LeftClick && mode!=DD_AfterCheck) { savetextureusefile(); waitleftbutton=true; } if (mode==DD_Draw) { glColor4f(buttontextlit); rectangle(661,120,775,264); } if (mode==DD_Check) if (leftclickinwindow(661,121,774,263) && mouseinwindow(661,121,774,260)) fscnselected=min(fscnbarpos+(my-121) / 10,filenum(prjlist)-1); if ((mode ==DD_Check) && mouseinwindow(661,121,774,263)) fscnbarpos-=wheel*4; scroller(775,120,790,264,15,15,filenum(prjlist),14,fscnbarpos,mode); if (mode==DD_Draw) { pf = prjlist; for (x=1;x<=fscnbarpos;x++) pf=pf->next; for (x=0;x<=13;x++) { if (pf!=NULL) { if (fscnbarpos+x==fscnselected) glColor4f(col4); else glColor4f(buttontextlit); glRasterPos2i(665,130+x*10); strcpy(st,pf->filedata.cFileName); glPrint(st,base2,18); pf=pf->next; } } glColor4f(buttontextlit); sprintf(s,"%d PROJECTS.",filenum(prjlist)); glRasterPos2i(683,277); glPrint(s,base2); } glColor4f(1,1,1,1); if ((button(686,283,771,299,texbutton1,0,96.0/256.0,85.0/256.0,112.0/256.0,false,mode) == DDgui_LeftClick) && (mode!=DD_AfterCheck)) { pf = prjlist; for (x=1;x<=fscnselected;x++) pf=pf->next; //sprintf(s,"%s%s",scenedir,pf->filedata.cFileName); memset(lastfilename,0,256); memcpy(lastfilename,pf->filedata.cFileName,strlen(pf->filedata.cFileName)-4); sprintf(s,"%s%s",projectdir,pf->filedata.cFileName); //loadaDDictscene(*actualscene,NULL,s,true,true,true,true,true); LoadProject(s); modellviews[3].cam=actualscene->editview; modellviews[3].cam2=actualscene->editview; tTexture *tex=texturelist; while ((tex!=NULL) && (tex->number!=selectedtexture)) tex=tex->next; memcpy(generatedtexture.commands,tex->commands,sizeof(generatedtexture.commands)); memcpy(generatedtexture.texts,tex->texts,sizeof(generatedtexture.texts)); generatedtexture.commandnum=tex->commandnum; //memcpy(generatedtexture.layers,tex->layers,sizeof(generatedtexture.layers)); for (y=0;y<=3;y++) { glBindTexture(GL_TEXTURE_2D, texlayers[y]); glTexImage2D(GL_TEXTURE_2D,0,3,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,generatedtexture.layers[y]); } if (materiallist!=NULL) { matselected=0; material *mat=materiallist; for (x=1;x<=matselected;x++) mat=mat->next; mattexture=mat->handle; } waitleftbutton=true; } if (button(685,300,770,316,texbutton1,0,144.0/256.0,85.0/256.0,160.0/256.0,false,mode) == DDgui_LeftClick) { char *ss=readline("Enter Filename (.scn not needed)",210,0,base2,lastfilename); if (ss!="") { //sprintf(s,"%s%s.scn",scenedir,ss); //saveaDDictscene(*actualscene,NULL,s,scntexturesave, scncamerasave, scnselectionsave, scnlightsave, scnobjectsave); memset(lastfilename,0,256); memcpy(lastfilename,ss,strlen(ss)); sprintf(s,"%s%s.64k",projectdir,ss); SaveProject(s); } } if (button(685,317,770,333,texbutton1,0,160.0/256.0,85.0/256.0,176.0/256.0,false,mode) == DDgui_LeftClick) { char *ss=readline("Enter Filename (.scn not needed)",210,0,base2,""); if (ss!="") { sprintf(s,"%s%s.m64",minimaldir,ss); //SaveMinimalScene(*actualscene,NULL,s); saveminimalproject(s,2); } } /*RadioButton(681,341,scntexturesave,"TEXTURES",mode); RadioButton(681,355,scncamerasave,"CAMERAS",mode); RadioButton(681,369,scnselectionsave,"SELECTIONS",mode); RadioButton(681,383,scnlightsave,"LIGHTS",mode); RadioButton(681,397,scnobjectsave,"OBJECTS",mode);*/ }
void main(void) { int gdriver = DETECT, gmode, errorcode; void *body,*food,*tail1,*tail2,*tail3,*tail4,*head1,*head2,*head3,*head4; int x, y,X[5000],Y[5000],i=3, maxx,maxy,speed=100,bo=10,t[10],score=0,hscore=20; unsigned int size; char a='6',b,scor[4],hs[4]; int k=2,l,r1,r2,f=0,z=100,first=0,second=1;; r1=300; r2=350; ifstream infile("c:\tc\bin\rattle.txt"); infile.getline(hs,4); infile.close(); hscore = atoi(hs); /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } maxx = getmaxx(); maxy = getmaxy(); y = 160; x = 80; for(int j=0; j<=3; j++) { X[i-j]=x-bo*(j+1); Y[i-j]=y; } //body setfillstyle(1,2); bar(10,10,20,20); setcolor(0); setlinestyle(0,1,3); line(9,9,21,21); line(9,21,21,9); size = imagesize(10,10,20,20); body = malloc(size); getimage(10,10,20,20,body); cleardevice(); setcolor(0); //tail1-right t[0]=20; t[1]=10; t[2]=10; t[3]=10; t[4]=20; t[5]=15; t[6]=10; t[7]=20; t[8]=20; t[9]=21; fillpoly(5, t); size = imagesize(10,10,20,21); tail1 = malloc(size); getimage(10,10,20,21,tail1); cleardevice(); //tail2-left t[0]=10; t[1]=10; t[2]=20; t[3]=10; t[4]=10; t[5]=15; t[6]=20; t[7]=20; t[8]=10; t[9]=21; fillpoly(5, t); size = imagesize(10,10,20,21); tail2 = malloc(size); getimage(10,10,20,21,tail2); cleardevice(); //tail3-up t[0]=10; t[1]=20; t[2]=10; t[3]=10; t[4]=15; t[5]=20; t[6]=20; t[7]=10; t[8]=20; t[9]=21; fillpoly(5, t); size = imagesize(10,10,20,21); tail3 = malloc(size); getimage(10,10,20,21,tail3); cleardevice(); //tail4-down t[0]=10; t[1]=10; t[2]=10; t[3]=21; t[4]=15; t[5]=10; t[6]=20; t[7]=21; t[8]=20; t[9]=10; fillpoly(5, t); size = imagesize(10,10,20,21); tail4 = malloc(size); getimage(10,10,20,21,tail4); cleardevice(); //head1-right setlinestyle(1,1,1); setcolor(2); fillellipse(10,10,10,5); setcolor(4); //eyes fillellipse(15,7,1,1); fillellipse(15,13,1,1); size = imagesize(10,5,20,15); head1 = malloc(size); getimage(10,5,20,15,head1); //head2-left //eyes fillellipse(5,7,1,1); fillellipse(5,13,1,1); size = imagesize(0,5,10,15); head2 = malloc(size); getimage(0,5,10,15,head2); cleardevice(); //head3-up //eyes setcolor(2); fillellipse(12,12,5,10); setcolor(4); fillellipse(9,6,1,1); fillellipse(15,6,1,1); size = imagesize(7,2,18,12); head3 = malloc(size); getimage(7,2,18,12,head3); //head4-down //eyes fillellipse(9,17,1,1); fillellipse(15,17,1,1); size = imagesize(7,12,18,22); head4 = malloc(size); getimage(7,12,18,22,head4); cleardevice(); //food setcolor(15); setfillstyle(1,15); fillellipse(10,10,3,5); size = imagesize(5,3,15,17); food = malloc(size); getimage(5,3,15,17,food); cleardevice(); /* repeat until a key is pressed */ maxx=getmaxx(); maxy=getmaxy(); setlinestyle(0,1,3); setcolor(9); rectangle(0,0,maxx,maxy); setlinestyle(0,1,2); line(maxx-150,0,maxx-150,maxy); setcolor(8); setfillstyle(1,8); bar(maxx-147,3,maxx-3,63); setcolor(12); int maze=1; if(maze==1) { setfillstyle(1,6); bar(4,4,maxx-154,14); bar(4,4,14,maxy-4); bar(4,maxy-4,maxx-154,maxy-14); bar(maxx-154-10,4,maxx-154,maxy-4); } settextstyle(0,0,1); delay(300); outtextxy(maxx-125,30,"RATTLE SNAKE"); delay(300); setcolor(11); setlinestyle(0,1,2); rectangle(maxx-145,65,maxx-5,205); outtextxy(maxx-128,70,"INSTRUCTIONS"); delay(200); setcolor(6); outtextxy(maxx-140,90,"Commands Key"); delay(300); setcolor(8); outtextxy(maxx-140,110," Move Up 8"); delay(50); outtextxy(maxx-140,130," Move Down 5"); delay(50); outtextxy(maxx-140,150," Move Right 6"); delay(50); outtextxy(maxx-140,170," Move Left 4"); delay(50); outtextxy(maxx-140,190," Exit 0"); delay(200); setcolor(12); setlinestyle(0,1,2); rectangle(maxx-145,210,maxx-5,350); setcolor(1); outtextxy(maxx-130,220,"Player's Name"); setcolor(15); outtextxy(maxx-100,230,"Yellow"); setcolor(4); delay(200); itoa(score,scor,10); outtextxy(maxx-140,250,"Score"); outtextxy(maxx-50,250,scor); delay(200); setcolor(10); outtextxy(maxx-140,280,"Level"); delay(200); setcolor(13); outtextxy(maxx-140,310,"Maze 1"); delay(200); setcolor(14); outtextxy(maxx-140,340,"High Score "); outtextxy(maxx-50,340,hs); for(j=0; j<=1000; j++) { putpixel(random(maxx-150),random(maxy),6); delay(1); } while (a!='0') { // plot new image if(a=='6') putimage(x, y, head1, XOR_PUT); if(a=='4') putimage(x, y, head2, XOR_PUT); if(a=='8') putimage(x, y, head3, XOR_PUT); if(a=='5') putimage(x, y, head4, XOR_PUT); for(j=0; j<k; j++) { putimage(X[i-j], Y[i-j], body, XOR_PUT); } if((X[i-j-1]-X[i-j])<0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail1, XOR_PUT); if((X[i-j-1]-X[i-j])>0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail2, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])<0) putimage(X[i-j], Y[i-j], tail3, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])>0) putimage(X[i-j], Y[i-j], tail4, XOR_PUT); delay(speed); if(second==1) { setcolor(15); outtextxy(maxx-140,360,"Press Any Key..."); getch(); setcolor(0); outtextxy(maxx-140,360,"Press Any Key..."); a='6'; second=2; } if(first==1) { setcolor(15); outtextxy(maxx-140,360,"Congratulations "); sound(100); delay(300); nosound(); getch(); setcolor(0); outtextxy(maxx-140,360,"Congratulations "); second++; first=2; } // erase old image if(a=='6') putimage(x, y, head1, XOR_PUT); if(a=='4') putimage(x, y, head2, XOR_PUT); if(a=='8') putimage(x, y, head3, XOR_PUT); if(a=='5') putimage(x, y, head4, XOR_PUT); for(j=0; j<k; j++) { putimage(X[i-j], Y[i-j], body, XOR_PUT); } if((X[i-j-1]-X[i-j])<0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail1, XOR_PUT); if((X[i-j-1]-X[i-j])>0 && (Y[i-j-1]-Y[i-j])==0) putimage(X[i-j], Y[i-j], tail2, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])<0) putimage(X[i-j], Y[i-j], tail3, XOR_PUT); if((X[i-j-1]-X[i-j])==0 && (Y[i-j-1]-Y[i-j])>0) putimage(X[i-j], Y[i-j], tail4, XOR_PUT); if(f==0) { putimage(r1,r2,food,XOR_PUT); f=1; } z--; if((x>=r1 && y>=r2 && x<=r1+10 && y<=r2+10) || (x<=r1 && y<=r2 && x>=r1-10 && y>=r2-10) || z==0) { if(z!=0) { sound(800); delay(20); setcolor(0); score += 10; outtextxy(maxx-50,250,scor); itoa(score,scor,10); if(score>hscore) { strcpy(hs,scor); setfillstyle(1,1); bar(maxx-140,337,maxx-20,348); setcolor(14); outtextxy(maxx-50,340,hs); outtextxy(maxx-140,340,"High Score "); if(first==0) { first=1; } } setcolor(4); outtextxy(maxx-50,250,scor); k++; nosound(); } z=100; putimage(r1,r2,food,XOR_PUT); repr1: r1=random(450); if(r1<50) goto repr1; repr2: r2=random(400); if(r2<50) goto repr2; f=0; } i++; X[i]=x; Y[i]=y; b=a; if(kbhit()) { rep: a=getche(); if((b=='6' && a=='4') || (b=='4' && a=='6')) a=b; if((b=='8' && a=='5') || (b=='5' && a=='8')) a=b; if(a!='6' && a!='4' && a!='8' && a!='0' && a!='5') a=b; } /* if(x>maxx-170) x=0; if(y>maxy) y=0;*/ if(a=='8') y -= bo; if(a=='5') y += bo; if(a=='4') x -= bo; if(a=='6') x += bo; for(j=i+1; j<i-k; j--) { if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10)) { if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10)) { a='0'; } outtextxy(maxx-140,360,"C "); } if((X[i]>=X[j] && X[i]<=X[j]+10) || (X[i]<=X[j] && X[i]>=X[j]-10)) { if((Y[i]>=Y[j] && Y[i]<=Y[j]+10) || (Y[i]<=Y[j] && Y[i]>=X[j]-10)) { a='0'; } outtextxy(maxx-140,360,"C "); } } /* for(j=i; j<i-k; j--) { if((y>=Y[j] && y<=Y[j]+10) || (y<=Y[j] && y>=Y[j]-10)) { if((x>=X[j] && x<=X[j]+10) || (x<=X[j] && x>=X[j]-10)) { a='5'; } } if((x>=X[j] && x<=X[j]+10) || (x<=X[j] && x>=X[j]-10)) { if((y>=Y[j] && y<=Y[j]+10) || (y<=Y[j] && y>=Y[j]-10)) { a='5'; } } if(j==0) break; } */ /* if(x<=0) x=maxx-170; if(y<=0) y=maxy;*/ if(maze==1) { if(x<=14 || x>=maxx-184 || y<=14 || y>=maxy-14) { a='0'; } } } if(score>hscore) { ofstream onfile("c:\tc\bin\rattle.txt"); onfile<<scor; onfile.close(); } setcolor(15); outtextxy(maxx-140,390," Gameover"); sound(100); delay(400); nosound(); getch(); /* clean up */ free(body); closegraph(); }
void main() { int total_seats = 84 , total_seats_to_be_booked , display_time , total_seats_booked = 0; //int gd = DETECT , gm; //initgraph(&gd,&gm,"c:\\turboc3\\bgi"); clrscr(); welcome_screen(); closegraph(); clrscr(); int gd = DETECT , gm; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); setbkcolor(GREEN); for(A=0;A<=79;A++) cout<<g; cout << "\n\t\t\tTotal number of seats available is " << total_seats << endl; for(A=0;A<=79;A++) cout<<g; cout<<endl; cout << "\nEnter number of seats you want to book " << endl; cin>>total_seats_to_be_booked; exit_program(total_seats_to_be_booked); //cout << "\nEnter total number of display time " << endl; //cin >> display_time; total_seats_booked += total_seats_to_be_booked; //display_time = display_time * 1000; //cin >> total_seats_to_be_booked; //delay(3000); getch(); closegraph(); clrscr(); int graphics_driver = DETECT , graphics_mode; initgraph(&graphics_driver,&graphics_mode,"c:\\turboc3\\bgi"); setcolor(BLUE); setbkcolor(RED); setfillstyle(SOLID_FILL,BLUE); /*Draw seats of a theatre as square boxes */ char buff[1]; double c = 0; for(int j = 10 ; j < getmaxy()-50 ; j+=60) { for(int i = 10 ; i < getmaxx()-50 ; i+=50) { c++; gcvt(c ,3 , buff); // memset(buff , c , 0); setfillstyle(SOLID_FILL, BLUE); //textbackground(RED); bar(i , j , i + 35 , j + 35); rectangle(i , j , i + 35 , j + 35); setcolor(15); moveto( i+16 , j+16 ); // cout << c; outtext(buff); // print_seat_number(c , i , j); } } //delay(display_time); getch(); closegraph(); clrscr(); int seat_number; int seats[84]; memset(seats , 0 , 85); //gd = DETECT , gm; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); setbkcolor(BLUE); cout << "Enter seat numbers you want to book " << endl; for(int i = 0 ; i < total_seats_to_be_booked ; i++) { cout << "Seat number " << i + 1 << endl; cin >> seat_number; seats[seat_number] = 1; } getch(); clrscr(); gd = DETECT; initgraph(&gd , &gm , "c:\\turboc3\\bgi"); int k = 0; setcolor(BLUE); setbkcolor(RED); for(int p = 10 ; p <= getmaxy()-50 ; p+=60) { for(int i = 10 ; i <= getmaxx()-50 ; i+=50) { k++; gcvt(k ,3 , buff); if(seats[k] == 1) { setfillstyle(SOLID_FILL,GREEN); } else { setfillstyle(SOLID_FILL, BLUE); } bar(i , p , i + 35 , p + 35); rectangle(i , p , i + 35 , p + 35); setcolor(15); moveto( i+16 , p+16 ); outtext(buff); } } //delay(display_time); getch(); closegraph(); }
std::vector<std::vector<std::vector<cv::Point>>> MultiContourObjectDetector::findApproxContours( cv::Mat image, bool performOpening, bool findBaseShape) { // CREATE ACTIVE ZONE 80% AND 50% --------------------- Point centre(image.size().width / 2, image.size().height / 2); int deleteHeight = image.size().height * _deleteFocus; int deleteWidth = image.size().width * _deleteFocus; int deleteX = centre.x - deleteWidth / 2; int deleteY = centre.y - deleteHeight / 2; int attenuationHeight = image.size().height * _attenuationFocus; int attenuationWidth = image.size().width * _attenuationFocus; int attenuationX = centre.x - attenuationWidth / 2; int attenuationY = centre.y - attenuationHeight / 2; Rect erase(deleteX, deleteY, deleteWidth, deleteHeight); _deleteRect = erase; Rect ease(attenuationX, attenuationY, attenuationWidth, attenuationHeight); _attenuationRect = ease; // ---------------------------------------- bool imageTooBig = false; Mat newImage; if (image.size().height <= 400 || image.size().width <= 400) { Mat pickColor = image(Rect((image.size().width / 2) - 1, image.size().height - 2, 2, 2)); Scalar color = mean(pickColor); int increment = 2; newImage = Mat(Size(image.size().width + increment, image.size().height + increment), image.type()); newImage = color; Point nc(newImage.size().width / 2, newImage.size().height / 2); int incH = image.size().height; int incW = image.size().width; int incX = nc.x - incW / 2; int incY = nc.y - incH / 2; image.copyTo(newImage(Rect(incX, incY, incW, incH))); } else { imageTooBig = true; newImage = image; } Size imgSize = newImage.size(); Mat gray(imgSize, CV_8UC1); Mat thresh(imgSize, CV_8UC1); if (newImage.channels() >= 3) cvtColor(newImage, gray, CV_BGR2GRAY); else newImage.copyTo(gray); int minThreshold; if (performOpening) { // PERFORM OPENING (Erosion --> Dilation) int erosion_size = 3; int dilation_size = 3; if (imageTooBig) { erosion_size = 5; dilation_size = 5; } Mat element = getStructuringElement(0, Size(2 * erosion_size, 2 * erosion_size), Point(erosion_size, erosion_size)); erode(gray, gray, element); dilate(gray, gray, element); minThreshold = mean(gray)[0]; if (minThreshold < 90) minThreshold = 60; else if (minThreshold >= 90 && minThreshold < 125) minThreshold = 100; } threshold(gray, thresh, minThreshold, 255, THRESH_BINARY); #ifdef DEBUG_MODE imshow("Threshold", thresh); #endif vector<vector<Point>> contours; vector<Vec4i> hierarchy; vector<Point> hull, approx; map<int, vector<vector<Point>>> hierachedContours; map<int, vector<vector<Point>>> approxHContours; findContours(thresh, contours, hierarchy, CV_RETR_TREE, CHAIN_APPROX_NONE); #ifdef DEBUG_MODE Mat tempI(image.size(), CV_8UC1); tempI = Scalar(0); drawContours(tempI, contours, -1, cv::Scalar(255), 1, CV_AA); imshow("Contours", tempI); #endif vector<vector<Point>> temp; // CATALOG BY HIERARCHY LOOP for (int i = 0; i < contours.size(); i++) { #ifdef DEBUG_MODE tempI = Scalar(0); temp.clear(); temp.push_back(contours[i]); drawContours(tempI, temp, -1, cv::Scalar(255), 1, CV_AA); #endif int parent = hierarchy[i][3]; if (parent == -1) { if (hierachedContours.count(i) == 0) { // me not found hierachedContours.insert(pair<int, vector<vector<Point>>>(i, vector<vector<Point>>())); hierachedContours[i].push_back(contours[i]); } else { // me found continue; } } else { if (hierachedContours.count(parent) == 0) { // dad not found hierachedContours.insert(pair<int, vector<vector<Point>>>(parent, vector<vector<Point>>())); hierachedContours[parent].push_back(contours[parent]); } hierachedContours[parent].push_back(contours[i]); } } int minPoint, maxPoint; minPoint = _minContourPoints - _minContourPoints / 2.1; maxPoint = _minContourPoints + _minContourPoints / 1.5; // APPROX LOOP for (map<int, vector<vector<Point>>>::iterator it = hierachedContours.begin(); it != hierachedContours.end(); it++) { if (it->second[0].size() < 400) continue; #ifdef DEBUG_MODE tempI = Scalar(0); drawContours(tempI, it->second, -1, cv::Scalar(255), 1, CV_AA); #endif if (it == hierachedContours.begin() && it->second.size() < _aspectedContours) continue; for (int k = 0; k < it->second.size(); k++) { if (it->second[k].size() < _minContourPoints) { if (k == 0) // padre break; else // figlio continue; } convexHull(it->second[k], hull, false); double epsilon = it->second[k].size() * 0.003; approxPolyDP(it->second[k], approx, epsilon, true); #ifdef DEBUG_MODE tempI = Scalar(0); vector<vector<Point>> temp; temp.push_back(approx); drawContours(tempI, temp, -1, cv::Scalar(255), 1, CV_AA); #endif // REMOVE TOO EXTERNAL SHAPES ------------- if (imageTooBig) { Rect bounding = boundingRect(it->second[k]); #ifdef DEBUG_MODE rectangle(tempI, _deleteRect, Scalar(255)); rectangle(tempI, bounding, Scalar(255)); #endif bool isInternal = bounding.x > _deleteRect.x && bounding.y > _deleteRect.y && bounding.x + bounding.width < _deleteRect.x + _deleteRect.width && bounding.y + bounding.height < _deleteRect.y + _deleteRect.height; if (!isInternal) { if (k == 0) break; } } // -------------------------------------------------- if (!findBaseShape) { if (hull.size() < minPoint || hull.size() > maxPoint) { if (k == 0) // padre break; else // figlio continue; } } if (k == 0) { approxHContours.insert(pair<int, vector<vector<Point>>>(it->first, vector<vector<Point>>())); approxHContours.at(it->first).push_back(approx); } else { approxHContours[it->first].push_back(approx); } } } int maxSize = 0, maxID = 0; vector<vector<vector<Point>>> lookupVector; for (map<int, vector<vector<Point>>>::iterator it = approxHContours.begin(); it != approxHContours.end(); it++) { if (it->second.size() <= 1) continue; if (findBaseShape) { int totSize = 0; for (int k = 0; k < it->second.size(); k++) { totSize += it->second[k].size(); } if (totSize > maxSize) { maxSize = totSize; maxID = it->first; } } else { lookupVector.push_back(it->second); } } if (findBaseShape) { lookupVector.push_back(approxHContours.at(maxID)); } return lookupVector; }
void money_transfer() { char num,number[20],type[5];int n=0,t=0,coff=1; setcolor(15);settextstyle(2,0,5); setfillstyle(0,0); bar(20,120,100,180);bar(300,10,500,50); cleardevice();setbkcolor(0); outtextxy(30,314,"Enter the 10-digit Pin number:"); rectangle(260,314,600,334); num=0; while(num!=13) { setcolor(15);settextstyle(2,0,4); if(kbhit()) { num=getch(); if(isdigit(num) && num!=8 && n<100){ sprintf(number,"%c",num);outtextxy(265+n,314,"*");n+=10;} if(num==8 && n>0 && n<=100) {setfillstyle(0,1); bar(265+n,314,265+n-10,328);n-=10; } }} captcha(); num=0;n=0;w=0; while(num!=13) { settextstyle(2,0,4); if(kbhit()) { num=getch(); if(num!=8 && n<60){ sprintf(number,"%c",num); outtextxy(20+n,272,number);n+=10;} if(num==8 && n>0 && n<=60) {setfillstyle(1,15); bar(20+n,272,20+n-10,283);n-=10;} }} setfillstyle(0,0); bar(30,305,400,330); cleardevice();setbkcolor(0);num=0;bk(); setcolor(15);settextstyle(2,0,5); outtextxy(40,150,"accept the whole fare to transfer from your account?"); outtextxy(70,200,"yes(y)");outtextxy(130,200,"no(n)"); num=getch(); sprintf(number,"%c",num); outtextxy(40,230,number); if(num=='y') {cleardevice();setcolor(0);setcolor(3);settextstyle(2,0,5);bk(); outtextxy(50,240,"transaction is complete.successfully transmitted from your account."); } else { cleardevice();setcolor(3);settextstyle(2,0,5); outtextxy(50,240,"interupt caused.transaction stopped."); } }
void secure() { char cha,daff[30];int s=0; setcolor(15);settextstyle(2,0,5); cleardevice();setbkcolor(0); bk();setcolor(15);rectangle(0,0,getmaxx(),getmaxy()); //outtextxy(250,14,"username");rectangle(320,13,600,28); outtextxy(250,40,"password");rectangle(320,40,600,55); settextstyle(2,0,4);cha=0; while(cha!=13) { if(kbhit()) { cha=getch(); if(cha!=8 && s<=200) {sprintf(daff,"%c",cha);outtextxy(330+s,14,daff); s+=10;} if(cha==8 && s>0 && s<=210) {setfillstyle(0,1); bar(330+s,14,330+s-10,24);s-=10;} }} cha=0; s=0; while(cha!=13) { if(kbhit()) { cha=getch(); if(cha!=8 && s<200) {sprintf(daff,"%c",cha);outtextxy(330+s,40,"*");s+=10;} if(cha==8 && s>0 && s<=210) {setfillstyle(0,1); bar(330+s,42,330+s-10,50);s-=10;} }} cha=0; cleardevice();setbkcolor(0); setcolor(3);settextstyle(2,0,5); outtextxy(40,100,"Payment mode"); setcolor(4); outtextxy(40,130,"credit"); setcolor(15); outtextxy(40,140,"debit"); outtextxy(40,150,"net banking."); pay=0;cha=0; while(cha!=27) { if(kbhit()) { cha=getch(); if(cha==80 && pay<2) {pay++;select_pay(pay);} if(cha==72 && pay>0) {pay--;select_pay(pay);} if(cha==13) break; }} }
void InitSubPage(HWND Window,int pt_w,int pt_h,int pg_w,int pg_h) { HWND Mid; int xw,yw,i,j; char p[40]; int SaveColor; struct viewporttype SaveViewPort; WaitMessageEmpty(); MouseHidden(); getviewsettings(&SaveViewPort); SaveColor=getcolor(); Mid=WindowGetFather(Window); ScreenDispWidth=WindowGetWidth(Window)-10; ScreenDispHeight=WindowGetHeight(Window)-10; WinX=ScreenX=WindowGetLeft(Window)+WindowGetLeft(Mid); WinY=ScreenY=WindowGetTop(Window)+WindowGetTop(Mid); setviewport(WinX,WinY,WinX+ScreenDispWidth+9,WinY+ScreenDispHeight+9,1); setwritemode(COPY_PUT); setcolor(EGA_WHITE); bar(0,0,ScreenDispWidth+9,ScreenDispHeight+9); SCRscaleX=SubP->TotalX/ScreenDispWidth*1.05; SCRscaleY=SubP->TotalY/ScreenDispHeight*1.05; if (SCRscaleX>SCRscaleY) SCRscaleY=SCRscaleX; else SCRscaleX=SCRscaleY; xw=mXw=pg_w/SCRscaleX; yw=mYw=pg_h/SCRscaleY; ScreenX=ScreenX+5+(ScreenDispWidth-mXw)/2; ScreenY=ScreenY+5+(ScreenDispHeight-mYw)/2; //setcolor(EGA_DARKGRAY); //gray setcolor(12); setviewport(0,0,getmaxx(),getmaxy(),1); rectangle(ScreenX,ScreenY,ScreenX+xw,ScreenY+yw); setviewport(WinX,WinY,WinX+ScreenDispWidth+9,WinY+ScreenDispHeight+9,1); for (i=0;i<PG.Blocks;i++) { int x0,x1,y0,y1; mXw=ScreenX-WinX; mYw=ScreenY-WinY; x0=-PG.PageBlock[i].Xoffset*1000/25.4/SCRscaleX+mXw; y0=-PG.PageBlock[i].Yoffset*1000/25.4/SCRscaleY+mYw; x1=x0+pt_w/SCRscaleX; y1=y0+pt_h/SCRscaleY; if (PG.PageBlock[i].Reveser&1) setcolor(14); else setcolor(11); rectangle(x0,y0,x1,y1); } setwritemode(COPY_PUT); setcolor(SaveColor); setviewport(SaveViewPort.left,SaveViewPort.top,SaveViewPort.right, SaveViewPort.bottom,SaveViewPort.clip); MouseShow(); }
void *image_show( void *) /*analiza imagem*/ { Mat frameCopy; Mat frameAnalize; Mat result; mouseInfo.event=-1; while(1) { pthread_mutex_lock(&in_frame); frameCopy=frame; pthread_mutex_unlock(&in_frame); pthread_mutex_lock(&in_mouseInfo); if(mouseInfo.x > 100 && mouseInfo.y >100 && mouseInfo.event==EVENT_LBUTTONDOWN) { Cerro; printf("Change! \n"); Rect myDim(mouseInfo.x-25,mouseInfo.y-25, 50, 50); frameAnalize = frameCopy(myDim).clone(); frameAnalize.copyTo(frameAnalize); } else if(mouseInfo.event == -1) { Rect myDim(100,100, 50, 50); frameAnalize = frameCopy(myDim); frameAnalize.copyTo(frameAnalize); mouseInfo.event=-2; } pthread_mutex_unlock(&in_mouseInfo); /// Create the result matrix int result_cols = frameCopy.cols - frameAnalize.cols + 1; int result_rows = frameCopy.rows - frameAnalize.rows + 1; result.create( result_cols, result_rows, CV_32FC1 ); /// Do the Matching and Normalize int match_method=1; //1-5 matchTemplate( frameCopy, frameAnalize, result, match_method ); normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); /// Localizing the best match with minMaxLoc double minVal; double maxVal; Point minLoc; Point maxLoc; Point matchLoc; minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() ); /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better if( match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED ) { matchLoc = minLoc; } else { matchLoc = maxLoc; } /// Show me what you got rectangle( frameCopy, matchLoc, Point( matchLoc.x + frameAnalize.cols , matchLoc.y + frameAnalize.rows ), Scalar::all(0), 2, 8, 0 ); rectangle( result, matchLoc, Point( matchLoc.x + frameAnalize.cols , matchLoc.y + frameAnalize.rows ), Scalar::all(0), 2, 8, 0 ); /// make a dif with the original and the matched Rect myDim2(matchLoc.x,matchLoc.y,50 , 50); Mat frameAnalizado = frameCopy(myDim2).clone(); Mat subt = frameAnalize - frameAnalizado; /// Make a simple text to debug char str[256]; sprintf(str, "x:%d/y:%d", matchLoc.x, matchLoc.y); putText(frameCopy, str, cvPoint(30,30), FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(200,200,250), 1, CV_AA); sprintf(str, "maxVal:%.8f/minVal:%.8f", maxVal, minVal); putText(frameCopy, str, cvPoint(30,60), FONT_HERSHEY_COMPLEX_SMALL, 0.6, cvScalar(200,200,250), 1, CV_AA); /// Show de imgs imshow("image_show",frameCopy); namedWindow("image_show", CV_WINDOW_NORMAL); waitKey(30); imshow("analize",frameAnalize); namedWindow("analize", CV_WINDOW_NORMAL); waitKey(30); imshow("result",result); namedWindow("result", CV_WINDOW_NORMAL); waitKey(30); imshow("analizado",frameAnalizado); namedWindow("analizado", CV_WINDOW_NORMAL); waitKey(30); imshow("sub",subt); namedWindow("sub", CV_WINDOW_NORMAL); waitKey(30); usleep(10); } Cerro; printf("Image_show Down !\n"); return NULL; }
void Play(void)/*游戏实现过程*/ { srand((unsigned long)time(0)); food.flag=1;/*1表示需出现新食物,0表示食物已存在*/ snake.life=0;/*标志贪吃蛇活着*/ snake.dir=1;/*方向向右*/ snake.x[0]=300;snake.y[0]=240;/*定位蛇头初始位置*/ snake.x[1]=300;snake.y[1]=240; snake.node=2;/*贪食蛇节数*/ do { while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/ { if(food.flag==1)/*需要出现新食物*/ do { food.x=rand()%520+60; food.y=rand()%370+60; food.flag=0;/*标志已有食物*/ }while(food.x%10!=0||food.y%10!=0); if(food.flag==0)/*画出食物*/ { setcolor(GREEN); setlinestyle(3,0,3); rectangle(food.x,food.y,food.x+10,food.y+10); } for(i=snake.node-1;i>0;i--)/*实现蛇向前移动*/ { snake.x[i]=snake.x[i-1]; snake.y[i]=snake.y[i-1]; } switch(snake.dir) { case 1:snake.x[0]+=10;break;/*向右移*/ case 2: snake.x[0]-=10;break;/*向左移*/ case 3: snake.y[0]-=10;break;/*向上移*/ case 4: snake.y[0]+=10;break;/*向下移*/ } for(i=3;i<snake.node;i++) { if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])/*判断蛇是否吃到自己*/ { GameOver();/*游戏结束*/ snake.life=1;/*蛇死*/ break; } } if(snake.x[0]<60||snake.x[0]>590||snake.y[0]<50|| snake.y[0]>440)/*蛇是否撞到墙壁*/ { GameOver();/*游戏结束*/ snake.life=1; /*蛇死*/ break; } if(snake.x[0]==food.x&&snake.y[0]==food.y)/*判断是否吃到食物*/ { setcolor(0);/*用背景色遮盖调食物*/ rectangle(food.x,food.y,food.x+10,food.y+10); snake.node++;/*蛇的身体长一节*/ food.flag=1;/*需要出现新的食物*/ } setcolor(4);/*画蛇*/ for(i=0;i<snake.node;i++) { setlinestyle(0,0,1); rectangle(snake.x[i],snake.y[i],snake.x[i]+10, snake.y[i]+10); } delay(speed); setcolor(0);/*用背景色遮盖蛇的的最后一节*/ rectangle(snake.x[snake.node-1],snake.y[snake.node-1], snake.x[snake.node-1]+10,snake.y[snake.node-1]+10); } /*endwhile(!kbhit)*/ if(snake.life==1)/*如果蛇死就跳出循环*/ break; key=bioskey(0);/*接收按键*/ if(key==UP&&snake.dir!=4)/*判断是否往相反的方向移动*/ snake.dir=3; else if(key==DOWN&&snake.dir!=3)/*判断是否往相反的方向移动*/ snake.dir=4; else if(key==RIGHT&&snake.dir!=2)/*判断是否往相反的方向移动*/ snake.dir=1; else if(key==LEFT&&snake.dir!=1)/*判断是否往相反的方向移动*/ snake.dir=2; }while(key!=ESC);/*ESC键退出游戏*/ }
//Segment the chars from plate vector<CharSegment> OCR::segment(Plate plate){ Mat input=plate.plateImg; vector<CharSegment> output; //Threshold input image Mat img_threshold; //To make char image clearly // threshold(input, img_threshold, 60, 255, CV_THRESH_BINARY_INV); //Spain // threshold(input, img_threshold, 150~160, 255, CV_THRESH_BINARY); //China // TODO: IMPORTANT threshold(input, img_threshold, 175, 255, CV_THRESH_BINARY); //China if(debug) { imshow("OCR_Threshold_Binary", img_threshold); } Mat img_contours; img_threshold.copyTo(img_contours); //Find contours of possibles characters vector< vector< Point> > contours; findContours(img_contours, contours, // a vector of contours CV_RETR_EXTERNAL, // retrieve the external contours CV_CHAIN_APPROX_NONE); // all pixels of each contours // Draw blue contours on a white image cv::Mat result; img_threshold.copyTo(result); cvtColor(result, result, CV_GRAY2RGB); cv::drawContours(result, contours, -1, // draw all contours cv::Scalar(255,0,0), // in BLUE 1); // with a thickness of 1 //Start to iterate to each contour founded vector<vector<Point> >::iterator itc = contours.begin(); //Remove patch that are no inside limits of aspect ratio and area. while (itc!=contours.end()) { //Create bounding rect of object Rect mr = boundingRect(Mat(*itc)); rectangle(result, mr, Scalar(0,255,0)); //Possible chars in GREEN //Crop image Mat auxRoi(img_threshold, mr); if(verifySizes(auxRoi)){ auxRoi=preprocessChar(auxRoi); output.push_back(CharSegment(auxRoi, mr)); rectangle(result, mr, Scalar(0,0,255)); //Possible chars in RED } ++itc; } if(debug) { cout << "OCR number of chars: " << output.size() << "\n"; imshow("OCR Chars", result); cvWaitKey(0); } return output; }
progress::progress(window wd, bool visible) { create(wd, rectangle(), visible); }
cv::Point findEyeCenter(cv::Mat face, cv::Rect eye, std::string debugWindow) { cv::Mat eyeROIUnscaled = face(eye); cv::Mat eyeROI; scaleToFastSize(eyeROIUnscaled, eyeROI); // draw eye region rectangle(face, eye, 1234); //-- Find the gradient cv::Mat gradientX = computeMatXGradient(eyeROI); cv::Mat gradientY = computeMatXGradient(eyeROI.t()).t(); //-- Normalize and threshold the gradient // compute all the magnitudes cv::Mat mags = matrixMagnitude(gradientX, gradientY); //compute the threshold double gradientThresh = computeDynamicThreshold(mags, kGradientThreshold); //double gradientThresh = kGradientThreshold; //double gradientThresh = 0; //normalize for (int y = 0; y < eyeROI.rows; ++y) { double *Xr = gradientX.ptr<double>(y), *Yr = gradientY.ptr<double>(y); const double *Mr = mags.ptr<double>(y); for (int x = 0; x < eyeROI.cols; ++x) { double gX = Xr[x], gY = Yr[x]; double magnitude = Mr[x]; if (magnitude > gradientThresh) { Xr[x] = gX / magnitude; Yr[x] = gY / magnitude; } else { Xr[x] = 0.0; Yr[x] = 0.0; } } } imshow(debugWindow, gradientX); //-- Create a blurred and inverted image for weighting cv::Mat weight; GaussianBlur(eyeROI, weight, cv::Size(kWeightBlurSize, kWeightBlurSize), 0, 0); for (int y = 0; y < weight.rows; ++y) { unsigned char *row = weight.ptr<unsigned char>(y); for (int x = 0; x < weight.cols; ++x) { row[x] = (255 - row[x]); } } //imshow(debugWindow,weight); //-- Run the algorithm! cv::Mat outSum = cv::Mat::zeros(eyeROI.rows, eyeROI.cols, CV_64F); // for each possible gradient location // Note: these loops are reversed from the way the paper does them // it evaluates every possible center for each gradient location instead of // every possible gradient location for every center. printf("Eye Size: %ix%i\n", outSum.cols, outSum.rows); for (int y = 0; y < weight.rows; ++y) { const double *Xr = gradientX.ptr<double>(y), *Yr = gradientY.ptr<double>(y); for (int x = 0; x < weight.cols; ++x) { double gX = Xr[x], gY = Yr[x]; if (gX == 0.0 && gY == 0.0) { continue; } testPossibleCentersFormula(x, y, weight, gX, gY, outSum); } } // scale all the values down, basically averaging them double numGradients = (weight.rows*weight.cols); cv::Mat out; outSum.convertTo(out, CV_32F, 1.0 / numGradients); //imshow(debugWindow,out); //-- Find the maximum point cv::Point maxP; double maxVal; cv::minMaxLoc(out, NULL, &maxVal, NULL, &maxP); //-- Flood fill the edges if (kEnablePostProcess) { cv::Mat floodClone; //double floodThresh = computeDynamicThreshold(out, 1.5); double floodThresh = maxVal * kPostProcessThreshold; cv::threshold(out, floodClone, floodThresh, 0.0f, cv::THRESH_TOZERO); if (kPlotVectorField) { //plotVecField(gradientX, gradientY, floodClone); imwrite("eyeFrame.png", eyeROIUnscaled); } cv::Mat mask = floodKillEdges(floodClone); //imshow(debugWindow + " Mask",mask); //imshow(debugWindow,out); // redo max cv::minMaxLoc(out, NULL, &maxVal, NULL, &maxP, mask); } return unscalePoint(maxP, eye); }
void GLabel::paintEvent(QPaintEvent *e) { if (people == GLabel::She) { QRectF rectangle(50.0, 10.0, this->width() - 20 - 40, this->height() - 20); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(QBrush(QColor(255, 255, 255))); painter.drawRoundedRect(rectangle, 10, 10); QPointF points[3] = { QPointF(40, 33), QPointF(51, 29), QPointF(50, 38), }; QPen pen; pen.setColor(QColor(255, 255, 255)); painter.setPen(pen); painter.drawPolygon(points, 3); QPen pen1; pen1.setColor(Qt::black); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(pen1); painter.drawLine(points[0], points[1]); painter.drawLine(points[0], points[2]); } else if(people == GLabel::Me) { QRectF rectangle; // if (this->width() > 300) { // rectangle.setRect(10.0, 10.0, 300, this->height() - 20); // } else { // rectangle.setRect(10.0, 10.0, this->width() - 20 - 40, this->height() - 20); // } rectangle.setRect(10.0, 10.0, this->width() - 20 - 40, this->height() - 20); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setBrush(QBrush(QColor(0, 255, 0))); painter.drawRoundedRect(rectangle, 10, 10); QPointF points[3] = { QPointF(this->width()-40, 33), QPointF(this->width()-51, 28), QPointF(this->width()-51, 38), }; QPen pen; pen.setColor(QColor(0, 255, 0)); painter.setPen(pen); painter.drawPolygon(points, 3); QPen pen1; pen.setColor(Qt::black); painter.setPen(pen1); painter.setRenderHint(QPainter::Antialiasing, true); painter.drawLine(points[0], points[1]); painter.drawLine(points[0], points[2]); label_people->setGeometry(this->width() - 30, 18, 30, 30); // if (this->width() > 300) { // this->setGeometry(((QWidget*)this->parent())->width()- 15 - this->width(), this->y(), 360, (this->height())); // } else { // this->setGeometry(((QWidget*)this->parent())->width()- 15 - this->width(), this->y(), this->width(), (this->height())); // } this->setGeometry(((QWidget*)this->parent())->width()- 15 - this->width(), this->y(), this->width(), (this->height())); } }
void main() { char c,ch,ch1; FILE *ssa; int gdriver=DETECT,gmode,errorcode,x,y; initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi"); setbkcolor(18); for(int k=0;k<25;k++) { setcolor(3); delay(40); ellipse(320,240,0,360,200+k,50); } settextstyle(GOTHIC_FONT,0,5); outtextxy(170,210,"MINESWEEPER"); getch(); setcolor(15); print:clearviewport(); settextstyle(TRIPLEX_FONT,0,2); setcolor(3); rectangle(80,130,570,240); rectangle(85,135,565,235); outtextxy(100,140," BEGINNER LEVEL1: 9X9 GRID 10 MINES"); outtextxy(100,170,"INTERMEDIATE LEVEL2:10X10 GRID 16 MINES"); outtextxy(100,200," ADVANCED LEVEL3:13X13 GRID 30 MINES"); settextstyle(DEFAULT_FONT,0,1); outtextxy(250,250,"ENTER THE LEVEL:"); outtextxy(100,380,"PRESS ESCAPE TO QUIT"); outtextxy(100,410,"PRESS F1 FOR HELP"); outtextxy(100,440,"PRESS F2 FOR CONTROLS"); c=getche(); clearviewport(); if (c=='1') { x=minx=140;y=miny=120;mines=flag1=10;grid=9; } else if(c=='2') { x=minx=120;y=miny=110;flag1=mines=16;grid=10; } else if(c=='3') { x=minx=60;y=miny=70;mines=flag1=30;grid=13; } else if(c==27) exit(1); else if(c==';'||c=='<') { clearviewport(); if(c==';') ssa=fopen("c:\\turboc3\\sp.txt","r"); if(c=='<') ssa=fopen("c:\\turboc3\\sp1.txt","r"); while((ch1=fgetc(ssa))!= EOF) printf("%c",ch1); printf("\nPRESS ANY KEY TO EXIT"); getch(); rewind(ssa); goto print; } else goto print; maxx=minx+(grid-1)*40; maxy=miny+(grid-1)*30; setbkcolor(15); setcolor(8);//box colour for(int i=0;i<grid;i++) for(int j=0;j<grid;j++) { rectangle(minx+i*40,miny+j*30,minx+(i+1)*40,miny+(j+1)*30); setfillstyle(SOLID_FILL,15); bar(minx+5+i*40,miny+5+j*30,minx+35+i*40,miny+25+j*30); rectangle(minx+5+i*40,miny+5+j*30,minx+35+i*40,miny+25+j*30); } settextstyle(TRIPLEX_FONT,0,5); setcolor(3); outtextxy(190,10,"MINESWEEPER"); settextstyle(DEFAULT_FONT,0,1); minegen(); do { ch=getche(); setcolor(8); //resets box colorto frame color if(ch=='f'||ch=='F') { setcolor(1); flag(x,y); } if(ch=='s'||ch=='S') { setcolor(4); open(x,y); } if(ch==27) exit(1); if((x==minx&&ch==75)||(y==maxy&&ch==80)||(x==maxx&&ch==77)||(y==miny&&ch==72)) setcolor(4); else rectangle(x+5,y+5,x+35,y+25); switch(ch) { case 72:if(y>miny) y=y-30; break; case 80:if(y<maxy) y=y+30; break; case 75:if(x>minx) x=x-40; break; case 77:if(x<maxx) x=x+40; break; } setcolor(4); rectangle(x+5,y+5,x+35,y+25); }while(1); }
void ScanWiew::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { QColor cred(255,0,0); QColor cgreen(0,100,0); QColor cgreen2(0,150,0); QColor cblue(0,0,255); QPen pred(cred); QPen pgreen(cgreen); QPen pgreen2(cgreen2); QPen pblue(cblue); painter->setPen(pgreen); //QFont fcnew("Coruier new", 10, QFont::Normal); QFontMetrics fm(painter->font()); int pixelsHeight = fm.height(); int lineCnt = laserRangeInMeter/arcDistanceInMeter; for(int i = 1; i <= lineCnt; i++) { QRectF rectangle(-(i*arcDistanceInPixels), -(i*arcDistanceInPixels), i*2*arcDistanceInPixels,i*2*arcDistanceInPixels); int spanAngle = endAngle - startAngle+5; painter->drawArc(rectangle, ((int)startAngle+90-5)*16, (spanAngle+5)*16); int x = -::sin((startAngle-5)*TwoPi/360)*(i*arcDistanceInPixels); int y = -::cos((startAngle-5)*TwoPi/360)*(i*arcDistanceInPixels); char str[100]; sprintf(str,"%d",i*(int)arcDistanceInMeter); int pixelsWide = fm.width(str); QPoint ptl(x-pixelsWide,y); QPoint pbr(x,y+pixelsHeight); QRect rt(ptl,pbr); painter->drawText(rt, Qt::AlignCenter, (QString)(str)); x = -::sin((endAngle+5)*TwoPi/360)*(i*arcDistanceInPixels); y = -::cos((endAngle+5)*TwoPi/360)*(i*arcDistanceInPixels); QPoint ptl1(x,y); QPoint pbr1(x+pixelsWide,y+pixelsHeight); QRect rt1(ptl1,pbr1); painter->drawText(rt1, Qt::AlignCenter, (QString)(str)); } lineCnt = (endAngle - startAngle)/angleDelta; double ang = startAngle; int distance = (laserRangeInMeter/arcDistanceInMeter)*arcDistanceInPixels; for(int i = 0; i <= lineCnt ; i++) { painter->setPen(pgreen); int x = -::sin(ang*TwoPi/360)*(distance+5); int y = -::cos(ang*TwoPi/360)*(distance+5); painter->drawLine(0,0,x,y); char str[100]; sprintf(str,"%d",(int)ang); int pixelsWide = fm.width(str); x = -::sin(ang*TwoPi/360)*(distance+20); y = -::cos(ang*TwoPi/360)*(distance+20); QPoint ptl(x-pixelsWide/2,y - pixelsHeight/2); QPoint pbr(x+pixelsWide/2,y+pixelsHeight/2); QRect rt(ptl,pbr); painter->drawText(rt, Qt::AlignCenter, (QString)(str)); ang += angleDelta; } double olcek = arcDistanceInPixels/arcDistanceInMeter; //printf("olcek: %f\n",olcek); pgreen.setWidth(pgreen.width()+2); painter->setPen(pgreen2); for(int i = 0; i < pointCnt; i++) { painter->drawLine(0,0,-plist[i].y*olcek,-plist[i].x*olcek); } painter->setPen(pred); plinel_t *root = g_line_map.first; while(root != NULL) { if(root->line.length > 0.05 && root->point_cnt > 3 )//MIN_LENGTH_LINE_TO_SEND) { painter->drawLine(-root->line.sp.y*olcek,-root->line.sp.x*olcek,-root->line.ep.y*olcek,-root->line.ep.x*olcek); } root = root->next; } }
void main() { /* main()开始 */ int gdriver=VGA,gmode=VGAHI; int direc; char ch,ch2; int step,len,size,x,y,i,j; initgraph(&gdriver,&gmode,"c:\\tc"); Startgame: step=20; len=10; size=20; x=0; y=0; i=0; j=0; makebg(M,N); cleardevice(); setbkcolor(LIGHTBLUE); setwritemode(XOR_PUT); settextstyle(1,0,3); /*setcolor(GREEN); outtextxy(100,180,"Press <Q> to quit");*/ setcolor(RED); setfillstyle(LINE_FILL,RED); drawbg(bg,M,N,size,0,0); setcolor(WHITE); x+=len;y+=len; drawman(x,y,len); gotoxy(60,3); printf("M-by Manual"); gotoxy(60,6); printf("C-by Computer"); gotoxy(60,9); printf("Please choice:"); setcolor(WHITE); while(1) { ch=getch(); if(ch=='M'||ch=='m') { /* 人工控制 */ gotoxy(60,3); printf("A-Left "); gotoxy(60,6); printf("D-Right "); gotoxy(60,9); printf("W-Up "); gotoxy(60,12); printf("S-Down"); gotoxy(60,15); printf("Q-Quit"); while(1) { ch=getch(); drawman(x,y,len); if(ch=='Q'||ch=='q') { /*按了Q键,退出游戏*/ gotoxy(60,18); printf("You have press"); gotoxy(60,19); printf("Q key! Do you"); gotoxy(60,20); printf("Want to quit?"); gotoxy(60,21); printf("OK?[Y/N]"); while(1) { ch2=getch(); if(ch2=='Y'||ch2=='y') { closegraph(); clrscr(); exit(0); } else if(ch2=='N'||ch2=='n') goto Startgame; } } switch(ch) { case 'a': case 'A': if(j>0&&bg[i][j-1]==0) { if(x>step) { x-=step; j--; } } break; case 's': case 'S': if(i<M-1&&bg[i+1][j]==0) { if(y<479-step) { y+=step; i++; } } break; case 'd': case 'D': if(j<N-1&&bg[i][j+1]==0) { if(x<639-step) { x+=step; j++; } } break; case 'w': case 'W': if(i>0&&bg[i-1][j]==0) { if(y>step) { y-=step; i--; } } break; default :break; } drawman(x,y,len); delay(800); if(i>=M-1&&j>=N-1) { setcolor(LIGHTGREEN); rectangle(450,300,620,380); setfillstyle(SOLID_FILL,LIGHTGRAY); floodfill(480,360,LIGHTGREEN); settextstyle(0,0,1); setcolor(MAGENTA); outtextxy(455,325,"You won the game!"); outtextxy(455,355,"Press Q to quit..."); while(1) { ch2=getch(); if(ch2=='Q'||ch2=='q') break; } closegraph(); clrscr(); exit(0); /* settextstyle(4,0,3); setcolor(RED); outtextxy(150,260,"YOU WIN!");*/ } } }/* 人工控制结束 */ else if(ch=='C'||ch=='c') { /* 电脑控制 */ /* direc表示上一步运动方向 */ /* 并表示下一步运动方向 */ /* 0~3分别表示 西、北、东、南 */ gotoxy(60,3); printf("Computer now"); gotoxy(60,6); printf("Run the maze"); gotoxy(60,9); printf("Automatically..."); direc=2; i=j=0; while(i<M-1||j<N-1) { delay(80000); drawman(x,y,len); switch(direc) { case 0: /* 以3,0,1的次序尝试 */ if(i<M-1&&bg[i+1][j]==0){ y+=step;i++; direc=3; } else if(j>0&&bg[i][j-1]==0){ x-=step;j--; direc=0; } else if(i>0&&bg[i-1][j]==0){ y-=step;i--; direc=1; } else { x+=step;j++; direc=2; } break; case 1: if(j>0&&bg[i][j-1]==0){ x-=step;j--; direc=0; } else if(i>0&&bg[i-1][j]==0){ y-=step;i--; direc=1; } else if(j<N-1&&bg[i][j+1]==0){ x+=step;j++; direc=2; } else{ y+=step;i++; direc=3; } break; case 2: if(i>0&&bg[i-1][j]==0){ y-=step;i--; direc=1; } else if(j<N-1&&bg[i][j+1]==0){ x+=step;j++; direc=2; } else if(i<M-1&&bg[i+1][j]==0){ y+=step;i++; direc=3; } else { x-=step;j--; direc=0; } break; case 3: if(j<N-1&&bg[i][j+1]==0){ x+=step;j++; direc=2; } else if(i<M-1&&bg[i+1][j]==0){ y+=step;i++; direc=3; } else if(j>0&&bg[i][j-1]==0){ x-=step;j--; direc=0; } else { y-=step;i--; direc=1; } break; default :break; } drawman(x,y,len); } gotoxy(60,12); printf("Finished!"); gotoxy(60,15); printf("Press any"); gotoxy(60,18); printf("Key to quit..."); getch(); closegraph(); clrscr(); exit(0); }/* 电脑控制结束 */ } }/* main()结束 */
main() { int gd = DETECT,gm; int maxx,maxy,x,y,button,prevx,prevy,temp1,temp2,key,color; char ch = 'f' ; // default free-hand drawing initgraph(&gd,&gm,"C:\\TC\\BGI"); maxx = getmaxx(); maxy = getmaxy(); setcolor(BLUE); rectangle(0,0,maxx,maxy); setcolor(WHITE); settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); outtextxy(maxx/2-180,maxy-28,"<a href="http://www.programmingsimplified.com"">www.programmingsimplified.com"</a>); draw_color_panel(); draw_shape_panel(); setviewport(1,1,maxx-1,maxy-1,1); restrictmouseptr(1,1,maxx-1,maxy-1); showmouseptr(); rectangle(2,2,518,427); setviewport(1,1,519,428,1); while(1) { if(kbhit()) { key = get_key(); if( key == 1 ) { closegraph(); exit(0); } } getmousepos(&button,&x,&y); if( button == 1 ) { if( x > 4 && x < 635 && y > 431 && y < 457 ) change_color( x, y ); else if ( x > 529 && x < 625 && y > 40 && y < 250 ) ch = change_shape( x, y ); temp1 = x ; temp2 = y ; if ( ch == 'f' ) { hidemouseptr(); while( button == 1 ) { line(temp1,temp2,x,y); temp1 = x; temp2 = y; getmousepos(&button,&x,&y); } showmouseptr(); } while( button == 1) getmousepos(&button,&x,&y); /* to avoid interference of mouse while drawing */ hidemouseptr(); if( ch == 'p') putpixel(x,y,getcolor()); else if ( ch == 'b' ) { setfillstyle(SOLID_FILL,getcolor()); bar(temp1,temp2,x,y); } else if ( ch == 'l') line(temp1,temp2,x,y); else if ( ch == 'e') ellipse(temp1,temp2,0,360,abs(x-temp1),abs(y-temp2)); else if ( ch == 'r' ) rectangle(temp1,temp2,x,y); else if ( ch == 'c' ) { ch = 'f'; // setting to freehand drawing clearviewport(); color = getcolor(); setcolor(WHITE); rectangle(2,2,518,427); setcolor(color); } showmouseptr(); } } }
vector<Point> Camera::Follow() //prima void { //float* contour=new float[height*width](); float* output=new float[height*width](); vector<float> temp = ToArray(Mat::zeros(height, width, CV_8UC1 )); output = &temp[0]; cout << "[START] Active Contour " << endl; // Follow the camera cout << "Following the camera ..."; cout << flush; Point center(-1,-1); Vec3b hsv; Mat mask, gray, HSV; Scalar lowerb, upperb; int erosion_size = 2, dilation_size = 10; Mat erodeElement = getStructuringElement(MORPH_RECT, Size(2 * erosion_size + 1, 2 * erosion_size + 1), Point(erosion_size, erosion_size) ); Mat dilateElement = getStructuringElement(MORPH_RECT, Size(2 * dilation_size + 1, 2 * dilation_size + 1), Point(dilation_size, dilation_size) ); vector<float> frameArray, maskArray; Mat ROI = Mat::zeros( height, width, CV_8UC1 ); int count = 0; double sum = 0; //while(waitKey(1) == -1) {//da togliere /*if (capture.read(frame) == NULL) { cout << "[ERROR] frame not read" << endl; return; }*/ //frame già settato clock_t startTime = clock(); // compute the time cvtColor(frame, gray, COLOR_RGB2GRAY); cvtColor(frame, HSV, COLOR_RGB2HSV); setMouseCallback("Frame", onMouse); if( drawing_box ) draw_box(&frame, roi); if(clicked) { // Init mask if(!haveMask) { // Take hsv from mouse center = initCenter; hsv = HSV.at<Vec3b>(center.y,center.x); haveMask = true; //cout << "HSV: " << hsv << endl; lowerb = Scalar(hsv.val[0] - 30, hsv.val[1] - 50, hsv.val[2] - 50); upperb = Scalar(hsv.val[0] + 30, hsv.val[1] + 50, hsv.val[2] + 50); //cout << "lowerb: " << lowerb << endl; //cout << "upperb: " << upperb << endl; ROI = Mat::zeros( height, width, CV_8UC1 ); rectangle( ROI, roi.tl(), roi.br(), Scalar(255), -1); sum = 0; count = 0; //benchmark } // Create the mask inRange(HSV, lowerb , upperb, mask); dilate(mask, mask, dilateElement); mask = mask.mul(ROI); //imshow("mask", mask); frameArray = ToArray(gray); maskArray = ToArray(mask); ActiveContour(&frameArray[0], output, contour, &maskArray[0], width, height, roi.br().y); Mat OUT = ToMat(output, height, width); OUT.convertTo(OUT, CV_8UC1); //imshow("Output", OUT); vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours(OUT, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point(0, 0)); vector<Rect> boundRect( contours.size() ); for( int i = 0; i < contours.size(); i++ ) { boundRect[i] = boundingRect( Mat(contours[i]) ); } /// Draw polygonal contour + bonding rects + circles Mat drawing = Mat::zeros( height, width, CV_8UC3 ); circle(frame, center, 5, Scalar(0,0,255), 5); for( int i = 0; i< contours.size(); i++ ) { if(boundRect[i].contains(center)) { drawContours( frame, contours, i, Scalar(255,255,255), 1, 8, vector<Vec4i>(), 0, Point() ); rectangle( frame, boundRect[i].tl(), boundRect[i].br(), Scalar(0,255,0), 2, 8, 0 ); // Center center.x = boundRect[i].tl().x + boundRect[i].size().width/2; center.y = boundRect[i].tl().y + boundRect[i].size().height/2; int x = boundRect[i].size().width; int y = boundRect[i].size().height; int v = (int)(sqrt((x/(y+EPS))*area)); int h = (int)(area/v); int deltax = (int)((h-y)/2); int deltay = (int)((v-x)/2); int tlx = boundRect[i].tl().x -deltax; int tly = boundRect[i].tl().y -deltay; int brx = boundRect[i].br().x +deltax; int bry = boundRect[i].br().y +deltay; tlx = (tlx < 0) ? 0 : tlx; brx = (brx > width) ? width : brx; tly = (tly < 0) ? 0 : tly; bry = (bry > height) ? height : bry; roi = Rect(Point(tlx,tly),Point(brx,bry)); ROI = Mat::zeros( height, width, CV_8UC1 ); rectangle( ROI, roi.tl(), roi.br(), Scalar(255), -1); rectangle( frame, roi.tl(), roi.br(), Scalar(0,0,255), 2, 8, 0 ); //imshow("ROI", ROI); break; } } } imshow("Frame", frame); sum += double( clock() - startTime ) / (double)CLOCKS_PER_SEC; count++; // } cout << sum / count << endl << flush; return contours.front(); }
void face_detector::face_marker_lbp(Mat *frame) { static vector<Rect> faces; static Mat frame_gray; cvtColor(*frame, frame_gray, COLOR_BGR2GRAY); equalizeHist(frame_gray, frame_gray); static String face_cascade_name = "lbpcascade_frontalface.xml"; static String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml"; static CascadeClassifier face_cascade; static CascadeClassifier eyes_cascade; static bool loaded = false; if (!loaded) { if(!face_cascade.load(face_cascade_name)) { fprintf(stderr, "Could not load face classifier cascade!"); exit(1); } if(!eyes_cascade.load( eyes_cascade_name)) { fprintf(stderr, "Could not load eye classifier cascade!"); exit(1); } } loaded = true; static Cgt_Rect _area; static Rect largestFace; static Mat smallImgROI; static Rect eyeArea; static Cgt_Eye _iris_point; static Rect leftEyeRect(0,0,0,0), rightEyeRect(0,0,0,0); static vector<Rect> eyes; static Point left_top, right_bottom; face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0, Size(40, 40)); if(faces.empty() == false) { //取最大的脸 largestFace.width=0; largestFace.height=0; for (vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++) { if ((r->width * r->height) > (largestFace.width * largestFace.height)) largestFace = *r; } // 将最大人脸区域赋给area _area.left = largestFace.x; _area.right = largestFace.x + largestFace.width; _area.top = largestFace.y; _area.bottom = largestFace.y + largestFace.height; ///////////针对最大的脸检测人眼//////////////////////////////// eyeArea = largestFace; eyeArea.height = eyeArea.height/1.2; //仅对人脸的上半部分检测人眼,以减少错误率 //调整一下参数,只对上半部分有时检测不出来 smallImgROI = (*frame)(eyeArea); eyes_cascade.detectMultiScale(smallImgROI, eyes, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) ); if(eyes.size()>=2) { //必须至少有两只眼被检出 vector<Rect>::const_iterator nr = eyes.begin(); leftEyeRect = *nr; nr++; rightEyeRect = *nr; } else { //fprintf(stderr, "必须至少有两只眼被检出!\n"); return; } _iris_point.xleft = cvRound(largestFace.x + leftEyeRect.x + leftEyeRect.width*0.5); //左眼中心的x坐标 _iris_point.yleft = cvRound(largestFace.y + leftEyeRect.y + leftEyeRect.height*0.5); //左眼中心的y坐标 _iris_point.xright = cvRound(largestFace.x + rightEyeRect.x + rightEyeRect.width*0.5); //右眼中心的x坐标 _iris_point.yright = cvRound(largestFace.y + rightEyeRect.y + rightEyeRect.height*0.5); //右眼中心的y坐标 //对眼睛的后期验证: //不允许左眼在右眼右边 // if(iris_point.xleft >= iris_point.xright ) // fprintf(stderr, "11111111111"), nRetCode = false; //不允许眼睛在边界(由于,初始化的值为0,这也意味着如果少于两个眼检测出来,则认为检测失败) if ((_iris_point.xleft==0) || (_iris_point.yleft==0) ||(_iris_point.xright==0) || (_iris_point.yright==0) ) return; //不允许两只眼上下倾斜过多(也防止一些误检) if (abs(_iris_point.yright-_iris_point.yleft) > (largestFace.width/3) ) return; //不允许两只眼左右间距小于1/4人脸宽度(也防止一些误检) if (abs(_iris_point.xright-_iris_point.xleft) < (largestFace.width/4) ) return; //画出框到的人脸,验证调试用 left_top.x = _area.left; left_top.y = _area.top; right_bottom.x = _area.right; right_bottom.y = _area.bottom; rectangle(*frame, left_top, right_bottom, CV_RGB(0,255,0), 2, 8, 0); left_top.x = _iris_point.xleft; left_top.y = _iris_point.yleft; right_bottom.x = left_top.x; right_bottom.y = left_top.y; rectangle(*frame, left_top, right_bottom, CV_RGB(90, 255, 0), 2, 8, 0); left_top.x = _iris_point.xright; left_top.y = _iris_point.yright; right_bottom.x = left_top.x; right_bottom.y = left_top.y; rectangle(*frame, left_top, right_bottom, CV_RGB(0, 255, 0), 2, 8, 0); } }
bool assemble(widget& parent_widget, std::string const& caption, rectangle& rect = rectangle(), button_function_t function_on_click = []() -> bool { return true; }) { if (!this->create(WC_BUTTON, caption, rect, WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, NULL, parent_widget.get_handle())) { return false; } this->function_on_click = function_on_click; this->set_message_handlers(); return true; }
bool face_detector::get_face_parameters(Mat &matImg) { bool nRetCode = false; vector<Rect> faces; IplImage *orig_img = cvCloneImage(input_img); matImg = orig_img; cascadeFace.detectMultiScale(matImg, faces, 1.1, 2, 0, Size(40, 40)); if(faces.empty() == false) { //取最大的脸 Rect largestFace; largestFace.width=0; largestFace.height=0; for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++) { if( (r->width * r->height) > (largestFace.width * largestFace.height) ) largestFace = *r; } // 将最大人脸区域赋给area area.left = largestFace.x; area.right = largestFace.x + largestFace.width; area.top = largestFace.y; area.bottom = largestFace.y + largestFace.height; /*********/ //printf("left:%d, right: %d, top: %d, bottom: %d\n", area.left, area.right, area.top, area.bottom); /*********/ ///////////针对最大的脸检测人眼//////////////////////////////// Mat smallImgROI; Rect eyeArea = largestFace; eyeArea.height = eyeArea.height/1.2; //仅对人脸的上半部分检测人眼,以减少错误率 //调整一下参数,只对上半部分有时检测不出来 smallImgROI = matImg(eyeArea); Rect leftEyeRect(0,0,0,0), rightEyeRect(0,0,0,0); if(useSingleEyeClassifier) { // 使用双眼一起的单分类器检测眼 vector<Rect> eyes; cascadeEye.detectMultiScale( smallImgROI, eyes, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) ); if(eyes.size()>=2) { //必须至少有两只眼被检出 vector<Rect>::const_iterator nr = eyes.begin(); leftEyeRect = *nr; nr++; rightEyeRect = *nr; } else { fprintf(stderr, "必须至少有两只眼被检出!\n"); } } else { //使用左右眼分开的两个分类器检测眼 vector<Rect> leftEye, rightEye; cascadeLeftEye.detectMultiScale( smallImgROI, leftEye, 1.1, 2, CV_HAAR_SCALE_IMAGE, Size(20, 20) ); cascadeRightEye.detectMultiScale( smallImgROI, rightEye, 1.1, 2, CV_HAAR_SCALE_IMAGE, Size(20, 20) ); if(leftEye.empty() == false) leftEyeRect = *(leftEye.begin()); if(rightEye.empty() == false) rightEyeRect = *(rightEye.begin()); } iris_point.xleft = cvRound(largestFace.x + leftEyeRect.x + leftEyeRect.width*0.5); //左眼中心的x坐标 iris_point.yleft = cvRound(largestFace.y + leftEyeRect.y + leftEyeRect.height*0.5); //左眼中心的y坐标 iris_point.xright = cvRound(largestFace.x + rightEyeRect.x + rightEyeRect.width*0.5); //右眼中心的x坐标 iris_point.yright = cvRound(largestFace.y + rightEyeRect.y + rightEyeRect.height*0.5); //右眼中心的y坐标 nRetCode = true; //对眼睛的后期验证: //不允许左眼在右眼右边 // if(iris_point.xleft >= iris_point.xright ) // fprintf(stderr, "11111111111"), nRetCode = false; //不允许眼睛在边界(由于,初始化的值为0,这也意味着如果少于两个眼检测出来,则认为检测失败) if( (iris_point.xleft==0) || (iris_point.yleft==0) ||(iris_point.xright==0) || (iris_point.yright==0) ) fprintf(stderr, "22222222222222222\n"), nRetCode = false; //不允许两只眼上下倾斜过多(也防止一些误检) if(abs(iris_point.yright-iris_point.yleft) > (largestFace.width/3) ) fprintf(stderr, "3333333333333333\n"), nRetCode = false; //不允许两只眼左右间距小于1/4人脸宽度(也防止一些误检) if(abs(iris_point.xright-iris_point.xleft) < (largestFace.width/4) ) fprintf(stderr, "4444444444\n"), nRetCode = false; // 输入的gray_image水平是反转的,虽然并不影响这个函数的执行, // 但是为了达到左眼是右眼,右眼是左眼,在最后需要把左右眼对调一下。 // int tmpSwap; // tmpSwap = iris_point.xleft; // iris_point.xleft = iris_point.xright; // iris_point.xright = tmpSwap; // tmpSwap = iris_point.yleft; // iris_point.yleft = iris_point.yright; // iris_point.yright = tmpSwap; /******************/ //printf("xleft: %d, xright: %d, yleft: %d, yright: %d\n", iris_point.xleft, iris_point.xright, iris_point.yleft, iris_point.yright); /******************/ //画出框到的人脸,验证调试用 Point left_top, right_bottom; left_top.x = area.left; left_top.y = area.top; right_bottom.x = area.right; right_bottom.y = area.bottom; rectangle(matImg, left_top, right_bottom, CV_RGB(0,255,0), 2, 8, 0); left_top.x = iris_point.xleft; left_top.y = iris_point.yleft; right_bottom.x = left_top.x; right_bottom.y = left_top.y; rectangle(matImg, left_top, right_bottom, CV_RGB(90, 255, 0), 2, 8, 0); left_top.x = iris_point.xright; left_top.y = iris_point.yright; right_bottom.x = left_top.x; right_bottom.y = left_top.y; rectangle(matImg, left_top, right_bottom, CV_RGB(0, 255, 0), 2, 8, 0); } cvReleaseImage(&orig_img); return nRetCode; }
////////////////////////////*BARS*/////////////////////////////////////////////// number() { cleardevice(); rectangle(500,130,580,150);outtextxy(503,133,"EXIT"); rectangle(200,100,400,300); for(a=100;a<300;a=a+50) { line(200,a,400,a); } for(a=200;a<400;a=a+50) { line(a,100,a,300); } while(b<=15) { r=random1();r++; h=random2();h++; switch(h) { case 1:x=225;y=125;break; case 2:x=225;y=175;break; case 3:x=225;y=225;break; case 4:x=225;y=275;break; case 5:x=275;y=125;break; case 6:x=275;y=175;break; case 7:x=275;y=225;break; case 8:x=275;y=275;break; case 9:x=325;y=125;break; case 10:x=325;y=175;break; case 11:x=325;y=225;break; case 12:x=325;y=275;break; case 13:x=375;y=125;break; case 14:x=375;y=175;break; case 15:x=375;y=225;break; case 16:x=375;y=275;break; } if(r==16) { ex=x;ey=y; } switch(r) { case 1: outtextxy(x,y,c1); break; case 2: outtextxy(x,y,c2);break; case 3: outtextxy(x,y,c3);break; case 4: outtextxy(x,y,c4);break; case 5: outtextxy(x,y,c5);break; case 6: outtextxy(x,y,c6);break; case 7: outtextxy(x,y,c7);break; case 8: outtextxy(x,y,c8);break; case 9: outtextxy(x,y,c9);break; case 10: outtextxy(x,y,c10);break; case 11: outtextxy(x,y,c11);break; case 12: outtextxy(x,y,c12);break; case 13: outtextxy(x,y,c13);break; case 14: outtextxy(x,y,c14);break; case 15: outtextxy(x,y,c15);break; case 16: outtextxy(x,y,c16);break; } b++; } showmouseptr(); while(flag==0) { getmousepos(&button,&x,&y); if(button==1&&x>500&&x<580&&y>130&&y<150)exit(0); /////////////////main logic////////////// if(button==1&&((x>ex-75&&x<ex-25&&y<ey+25&&y>ey-25)||(x>ex-25&&x<ex+25&&y<ey-25&&y>ey-75)||(x>ex+25&&x<ex+75&&y>ey-25&&y<ey+25)||(x>ex-25&&x<ex+25&&y>ey+25&&y<ey+75))&&(x>200&&x<400&&y<300&&y>100)) { cx=x-(x%50);cy=y-(y%50); size=imagesize(cx+2,cy+2,cx+48,cy+48); buf=malloc(size); hidemouseptr(); getimage(cx+2,cy+2,cx+48,cy+48,buf); putimage(ex-23,ey-23,buf,0); free(buf); setfillstyle(SOLID_FILL,GREEN); bar(cx+2,cy+2,cx+48,cy+48); ex=cx+25;ey=cy+25; showmouseptr(); } ///////////////// } return(0); }
void StereoCapturer::computeStereo(float dt, bool display, bool save_Rectified){ double min, max; cv::Mat imgD,imgD2; int i,w,h; char buffer[255]; if(intrinsics.empty()||extrinsics.empty()){ cerr<< "Missing intrinsic and extrinsic file, file paths required at constructor"<<endl; return; } while(true){ if(current > finish){ cout<<"End of frames"<<endl; return; } sprintf(buffer,"%s%i.%s",loadS1.data(),current,ext1.data()); imgLeft = cv::imread(buffer,0); //left Image if(imgLeft.data == NULL){ cout<< "image "<< buffer<<" not found"<<endl; return; } sprintf(buffer,"%s%i.%s",loadS2.data(),current,ext2.data()); imgRight = cv::imread(buffer,0); //Right Image if(imgRight.data == NULL){ cout<< "image "<< buffer<<" not found"<<endl; return; } cout<<"Read image "<<loadS1.data()<<current<<endl; boost::posix_time::ptime startTime, stopTime; startTime = boost::posix_time::microsec_clock::local_time(); computeDisparity(imgDepth); stopTime = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration dur = stopTime - startTime; double milliseconds = dur.total_milliseconds(); cout<<"Time Passed "<<milliseconds<<" Milli seconds"<<endl; cout<<(int)imgDepth.step1(1)<<endl; cv::minMaxIdx(imgDepth, &min, &max); cout<<min<<" "<<max<<endl; cout<<255 / (max-min)<<endl; cv::normalize(imgDepth,imgD,0, 255,NORM_MINMAX,CV_8UC1); cv::minMaxIdx(imgD, &min, &max); cout<<min<<" "<<max<<endl; sprintf(buffer,"disparity/depthImage%i.png",current); imwrite(buffer,imgD); //Viewing purposes sprintf(buffer,"disparity/depthImage%i.DMX",current); saveMat(imgDepth,buffer,dt); //Processing purposes if(save_Rectified) { sprintf(buffer,"%sRectified%i.png",loadS1.data(),current); imwrite(buffer,imgLeftr); sprintf(buffer,"%sRectified%i.png",loadS2.data(),current); imwrite(buffer,imgRight); } if(display){ w = imgRightr.size().width; h = imgRightr.size().height; Mat canvas; Mat tImage; canvas.create(h, w*2, CV_8UC3); Mat canvasPart = canvas(Rect(0, 0, w, h)); cvtColor(imgLeftr, tImage, COLOR_GRAY2BGR); resize(tImage, canvasPart, canvasPart.size(), 0, 0, CV_INTER_AREA); Rect vroil(cvRound(roi1.x), cvRound(roi1.y), cvRound(roi1.width), cvRound(roi1.height)); rectangle(canvasPart, vroil, Scalar(0,0,255), 3, 8); canvasPart = canvas(Rect(w, 0, w, h)); cvtColor(imgRightr, tImage, COLOR_GRAY2BGR); resize(tImage, canvasPart, canvasPart.size(), 0, 0, CV_INTER_AREA); Rect vroir(cvRound(roi2.x), cvRound(roi2.y), cvRound(roi2.width), cvRound(roi2.height)); rectangle(canvasPart, vroir, Scalar(0,0,255), 3, 8); for( i = 0; i < canvas.rows; i += 16 ) line(canvas, Point(0, i), Point(canvas.cols, i), Scalar(0, 255, 0), 1, 8); // imshow("left Image",imgLeftr); // imshow("right Image", imgRightr); imshow("Rectified Images",canvas); imshow("Depth image",imgD); waitKey(0); } current++; } }