double_xyz rimginterface::MaximumInArea( tImgPlanar const& im, tAoi area ) { assert( im.is_mono8() ); int iy = area.sy(); const int x = area.px(); const int y = area.py(); int max = 0; while( iy-- ) { int ix = area.sx(); while( ix-- ) { int val = im[0][ y + iy ][ x + ix]; if( val > max ) { max = val; } } } vector<int32_xy> newxy( area.sx()*area.sy() + 1 ); // tixy *xy = newxy(); uint32_t maxcount = 0; iy = area.sy(); while( iy-- ) { int ix = area.sx(); while( ix-- ) { int val = im.pixel( uint32_xy( x + ix, y + iy ) ); if( val == max ) { newxy[ maxcount ].setx( x + ix ); newxy[ maxcount ].sety( y + iy ); maxcount++; } } } if( maxcount == 0 ) { assert( false ); } double dx = 0.0; double dy = 0.0; uint32_t count = maxcount; while( count ) { count--; dx += static_cast<double>(newxy[ count ].x()); dy += static_cast<double>(newxy[ count ].y()); } dx /= static_cast<double>(maxcount); dy /= static_cast<double>(maxcount); return double_xyz( dx, dy, max ); }
int main() { int buttons,x,y; char str[100]; int driver=VGA; int mode=VGAHI; initgraph(&driver,&mode,""); cleardevice(); rectangle(0,0,639,479); setfillstyle(SOLID_FILL,BLUE); bar(1,1,638,478); outtextxy(3,15,"move mouse using any button."); outtextxy(285,15,"quit"); setwritemode(XOR_PUT); if(init(2, 638, 8, 477)==0 ) /*调用init 函数对鼠标器初始化*/ {printf("Mouse or Mouse Driver Absent,P1ease install!"); delay(5000); closegraph(); exit(1); } x=320;y=240; cursor(x,y); /*置十字光标在屏幕中心*/ for(;;) { newxy(&x,&y,&buttons); if(x>=280&& x<=330 &&y>=12&&y<=33&& buttons) { cleardevice(); closegraph(); exit(0); } } }