void ImageViewer::watershedClick() { cv::Mat result; cv::Mat bgModel, fgModel; //cv::Rect rectangle(50, 70, image.cols-150, image.rows-180); cv::Rect rectangle2(10,100,380,180); cv::grabCut(image, // input image result, // segmentation result rectangle2,// rectangle containing foreground bgModel,fgModel, // models 5, // number of iterations cv::GC_INIT_WITH_RECT); // use rectangle // Get the pixels marked as likely foreground cv::compare(result, cv::GC_PR_FGD, result, cv::CMP_EQ); // Generate output image cv::Mat foreground(image.size(), CV_8UC3, cv::Scalar(255, 255, 255)); //image.copyTo(foreground, result); // bg pixels not copied // draw rectangle on original image //cv::rectangle(image, rectangle, cv::Scalar(255,255,255), 1); //foreground.create(image.size(),CV_8UC3); //foreground.setTo(cv::Scalar(255,255,255)); result = result & 1; image.copyTo(foreground, result); // bg pixels not copied //result = result & 1; imageDisplay(foreground); }
void display_digit(int n,float x,float y) { if(n==1) {rectangle2(x,y,1);rectangle6(x,y,1);} else if(n==2) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle4(x,y,1);rectangle5(x,y,1);rectangle7(x,y,1);} else if(n==3) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);} else if(n==4) {rectangle2(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);} else if(n==5) {rectangle1(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);} else if(n==6) {rectangle1(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle5(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);} else if(n==7) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle6(x,y,1);} else if(n==8) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle5(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);} else if(n==0) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle3(x,y,1);rectangle5(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);} else if(n==9) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);} }
void ImageRectangleTest::testRectangleSpec() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testRectangleSpec() begin"); ImageRectangle rectangle("1848x1291@(47,11)"); CPPUNIT_ASSERT(rectangle.size().width() == 1848); CPPUNIT_ASSERT(rectangle.size().height() == 1291); CPPUNIT_ASSERT(rectangle.origin().x() == 47); CPPUNIT_ASSERT(rectangle.origin().y() == 11); ImageRectangle rectangle2("1848x1291@47,11"); CPPUNIT_ASSERT(rectangle2.size().width() == 1848); CPPUNIT_ASSERT(rectangle2.size().height() == 1291); CPPUNIT_ASSERT(rectangle2.origin().x() == 47); CPPUNIT_ASSERT(rectangle2.origin().y() == 11); debug(LOG_DEBUG, DEBUG_LOG, 0, "testRectangleSpec() end"); }
void screen6() { char speed[6],inte[6]; glPointSize(1.0); write("GAME SOUND : ",100,600); write("YES ",450,600); write("NO ",600,600); write("SNAKE SPEED :",100,450); vitoa(n,speed); write(speed,400,450); write("SKILL LEVEL OF RAT:",100,300); vitoa(intelligence,inte); write(inte,500,300); write("NO OF PLAYERS :",100,200); write("ONE",480,200); write("TWO",680,200); glLoadIdentity(); carr=1; rectangle2(400,500); rectangle2(500,350); carr=0; rectangle2(400,400); rectangle2(500,250); carr=3; rectangle2(450,200); rectangle2(650,200); rectangle2(420,600); rectangle2(570,600); if(no_of_pl==1) rectangle3(455,205); else rectangle3(655,205); if(sound==1) rectangle3(425,605); else rectangle3(575,605); backbutton(); glFlush(); }
TEST(RectangleTest, Constructor) { Rectangle rectangle1; ASSERT_THAT(rectangle1.m_x, Eq(0)); ASSERT_THAT(rectangle1.m_y, Eq(0)); ASSERT_THAT(rectangle1.m_width, Eq(0)); ASSERT_THAT(rectangle1.m_height, Eq(0)); const int x2 = 1; const int y2 = 2; const int width2 = 3; const int height2 = 4; Rectangle rectangle2(x2, y2, width2, height2); ASSERT_THAT(rectangle2.m_x, Eq(x2)); ASSERT_THAT(rectangle2.m_y, Eq(y2)); ASSERT_THAT(rectangle2.m_width, Eq(width2)); ASSERT_THAT(rectangle2.m_height, Eq(height2)); }
int main() { sf::RenderWindow window(sf::VideoMode(1024, 683), "Testing"); window.setVerticalSyncEnabled(true); /*sf::Texture texture; sf::Texture ortonTexture; sf::Texture heartTexture; if (!texture.loadFromFile("TestCena2.png")) { std::cout << "Failed to load image\n"; } if (!ortonTexture.loadFromFile("TestOrton.png")) { std::cout << "Failed to load image\n"; } if (!heartTexture.loadFromFile("TestHeart.png")) { std::cout << "Failed to load image\n"; }*/ sf::Texture background; background.loadFromFile("ForestBackground.jpg"); sf::Sprite backgroundSprite; backgroundSprite.setTexture(background); sf::Image foxSpriteSheet; foxSpriteSheet.loadFromFile("FoxSprites.png"); int foxSpriteLength = 48; int currentFoxSprite = 6; sf::Texture foxTexture; sf::IntRect spriteBox(((currentFoxSprite % 3))*foxSpriteLength, ((currentFoxSprite % 4))*foxSpriteLength, foxSpriteLength, foxSpriteLength); foxTexture.loadFromImage(foxSpriteSheet, spriteBox); sf::Sprite foxSprite; foxSprite.setTexture(foxTexture); //window.draw(foxSprite); foxSprite.setPosition(0, 500); sf::FloatRect foxBox = foxSprite.getGlobalBounds(); sf::RectangleShape rectangle(sf::Vector2f(60, 60)); rectangle.setFillColor(sf::Color(255, 0, 0)); rectangle.setPosition(400, 500); sf::RectangleShape rectangle2(sf::Vector2f(60, 120)); rectangle2.setFillColor(sf::Color(255, 0, 0)); rectangle2.setPosition(800, 440); sf::FloatRect rectBox = rectangle.getGlobalBounds(); sf::FloatRect rect2Box = rectangle2.getGlobalBounds(); int animationCounter = 0; int jumpCounter = 0; int jumpVelo = -6; int jumpTime = 0; bool jumping = false; int jumpAccel = 1; /*sf::Sprite shape; shape.setTexture(texture); shape.setPosition(0, 0); sf::Sprite orton; orton.setTexture(ortonTexture); orton.setPosition(750,0); sf::Sprite heart; heart.setTexture(heartTexture); sf::Sprite heart2; heart2.setTexture(heartTexture); sf::FloatRect cenaBox = shape.getGlobalBounds(); sf::FloatRect ortonBox = orton.getGlobalBounds(); int kissCount = 0;*/ //shape.setScale(100.0f, 100.0f); //shape.setPosition(0, 0); //sf::CircleShape shape(100.f); //shape.setFillColor(sf::Color::Green); //sf::Vector2f position = shape.getPosition; while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } /*if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { shape.move(5, 0); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { shape.move(-5, 0); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { shape.move(0, -5); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { shape.move(0, 5); }*/ if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { foxBox = foxSprite.getGlobalBounds(); /*if (foxBox.intersects(rectBox) && foxBox.left<(rectBox.width + rectBox.left) || (foxBox.left+foxBox.width)>(rectBox.left)) { jumping = false; }*/ if (foxBox.intersects(rectBox)) { std::cout << "Testing\n"; } if (foxBox.intersects(rectBox) && (foxBox.top + foxBox.height) > (rectBox.top) && ((foxBox.left) + (foxBox.width)) >= (rectBox.left)) { // && ((foxBox.left) + (foxBox.width)) >= (rectBox.left) } else { foxSprite.move(3, 0); if (currentFoxSprite != 6 && currentFoxSprite != 7) { currentFoxSprite = 6; } else if (animationCounter % 10 != 9) { animationCounter++; } else { animationCounter = 0; currentFoxSprite++; } sf::IntRect newSpriteBox(((currentFoxSprite % 3))*foxSpriteLength, ((currentFoxSprite / 3))*foxSpriteLength, foxSpriteLength, foxSpriteLength); foxTexture.loadFromImage(foxSpriteSheet, newSpriteBox); foxSprite.setTexture(foxTexture); } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { foxBox = foxSprite.getGlobalBounds(); /*if (foxBox.intersects(rectBox) && foxBox.left<(rectBox.width + rectBox.left) || (foxBox.left + foxBox.width)>(rectBox.left)) { jumping = false; }*/ if (foxBox.intersects(rectBox) && (foxBox.top + foxBox.height) > (rectBox.top) && foxBox.left <= (rectBox.width + rectBox.left)) { // && foxBox.left<=(rectBox.width + rectBox.left) } else { foxSprite.move(-3, 0); if (currentFoxSprite != 3 && currentFoxSprite != 4) { currentFoxSprite = 3; } else if (animationCounter % 10 != 9) { animationCounter++; } else { animationCounter = 0; currentFoxSprite++; } sf::IntRect newSpriteBox(((currentFoxSprite % 3))*foxSpriteLength, ((currentFoxSprite / 3))*foxSpriteLength, foxSpriteLength, foxSpriteLength); foxTexture.loadFromImage(foxSpriteSheet, newSpriteBox); foxSprite.setTexture(foxTexture); } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { if (!jumping) { jumping = true; //jumpVelo = 50; jumpTime = 0; } } if (jumping) { jumpTime++; int calcedMove = jumpVelo*jumpTime + 0.5*jumpAccel*jumpTime*jumpTime; foxSprite.move(0, calcedMove); if (foxSprite.getPosition().y > 500) { foxSprite.setPosition(foxSprite.getPosition().x, 500); jumping = false; } foxBox = foxSprite.getGlobalBounds(); if (foxBox.intersects(rectBox) && (foxBox.top + foxBox.height) >= (rectBox.top)) { jumping = false; } } /*if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { foxSprite.move(0, -2); if (currentFoxSprite != 9 && currentFoxSprite != 10) { currentFoxSprite = 9; } else if (animationCounter % 10 != 9) { animationCounter++; } else { animationCounter = 0; currentFoxSprite++; } sf::IntRect newSpriteBox(((currentFoxSprite % 3))*foxSpriteLength, ((currentFoxSprite /3))*foxSpriteLength, foxSpriteLength, foxSpriteLength); foxTexture.loadFromImage(foxSpriteSheet, newSpriteBox); foxSprite.setTexture(foxTexture); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { foxSprite.move(0, 2); if (currentFoxSprite != 0 && currentFoxSprite != 1) { currentFoxSprite = 0; } else if (animationCounter % 10 != 9) { animationCounter++; } else { animationCounter = 0; currentFoxSprite++; } sf::IntRect newSpriteBox(((currentFoxSprite % 3))*foxSpriteLength, ((currentFoxSprite /3))*foxSpriteLength, foxSpriteLength, foxSpriteLength); foxTexture.loadFromImage(foxSpriteSheet, newSpriteBox); foxSprite.setTexture(foxTexture); }*/ //cenaBox = shape.getGlobalBounds(); //ortonBox = orton.getGlobalBounds(); window.clear(); //window.draw(shape); //window.draw(orton); window.draw(backgroundSprite); window.draw(foxSprite); window.draw(rectangle); window.draw(rectangle2); /*if (cenaBox.intersects(ortonBox)) { heart.setPosition(ortonBox.left, ortonBox.top); heart2.setPosition(cenaBox.left + cenaBox.width, cenaBox.top); window.draw(heart); window.draw(heart2); }*/ /*if ((ortonBox.left + ortonBox.width) > cenaBox.left) { window.draw(heart); std::cout << "Kiss " << ++kissCount << "\n"; }*/ window.display(); } return 0; }
void QtHistoTfuncPixmap::draw_histogram(QPainter* p) { //find the max value in our histogram max_histogram=0; float max_loghisto =0; float min_loghisto = log(1024.0*1024.0*1024.0); for(int iii=1; iii<graph_size; iii++) { max_histogram = max(max_histogram, data[iii]); if(data[iii]!=0) { max_loghisto = max((float)max_loghisto, (float)log(data[iii])); min_loghisto= min((float)min_loghisto, (float)log(data[iii])); } } //draw a background rect p->setPen(Qt::NoPen); p->setBrush(Qt::NoBrush); p->setPen(Qt::black); p->setBrush(Qt::white); p->drawRect(0,0,graph_size, graph_size); //reset our painter's brush p->setBrush(Qt::NoBrush); //draw a grid p->setPen(Qt::black); float fontsize = pensize*2.0; QFont serifFont("Arial", fontsize, QFont::Bold); p->setFont(serifFont); float grid_steps = (graph_size)/8.0; float grid_step=0; float loggrid_step=0; float logrid_stepincr=max_histogram/8.0; QString label; for(int ii=0; ii<9; ii++) { //linear scale if(logscale==0) { //x,y grid lines p->drawLine(grid_step, 0, grid_step, graph_size+border*0.25); p->drawLine(-border*0.25, grid_step, graph_size, grid_step); //x,y labels label.setNum((int)(grid_step),10); p->drawText( QRectF(grid_step-grid_steps/2.0, graph_size+border*0.4, grid_steps, fontsize*1.25), Qt::AlignCenter, label); p->drawText( QRectF(-border, graph_size-grid_step-4, grid_steps, fontsize*1.25), Qt::AlignCenter, label); } else { //x,y grid lines //Y AXIS LINES p->drawLine(grid_step, 0, grid_step, graph_size+border*0.25); label.setNum((int)(grid_step),10); p->drawText( QRectF(grid_step-grid_steps/2.0, graph_size+border*0.4, grid_steps, fontsize*2.0), Qt::AlignCenter, label); p->drawText( QRectF(-border, graph_size-grid_step-4, grid_steps, fontsize*2.0), Qt::AlignCenter, label); p->drawLine(-border*0.25, grid_step, graph_size, grid_step); } grid_step+=grid_steps; } if(hist_enable==1) { //dray our histogram bars //editor->fe_seleted // 1 = RGB// 2 = RGBA// 3 = R// 4 = G// 5 = B// 6 = A p->setBrush(Qt::NoBrush); p->setPen(Qt::NoPen); if(mode==0) p->setBrush( QColor(32,32,32, 255) ); else p->setBrush( QColor(64,64,64, 255) ); double height; int i; float xpos=0.0; //QPolygonF polygon; float iterp=0; if(max_histogram==0) max_histogram=1; for(i=0 ; i<graph_size; i++) { //linear scale if(logscale==1) { if(data[i]!=0) iterp = (double)(log(data[i])-min_loghisto)/(double)(max_loghisto-min_loghisto); else iterp = 0; } else { iterp = ((double)data[i]/(double)max_histogram); } if(iterp>1.0) iterp=1.0; if(iterp<0.0) iterp=0.0; height = (graph_size)*iterp; height = (int)(height+0.5); xpos = i; //polygon << QPointF(xpos, graph_size-height) ; QRectF rectangle((float)xpos-0.5, graph_size, 1.0, -height); p->drawRect(rectangle); } //p->drawPolygon(polygon, Qt::OddEvenFill); } if(cumfreq_enable==1) { //draw our cummulatative frequency //dray our histogram bars double sum =0; double maxsum =0; double height; for(int i=0 ; i<graph_size; i++) { maxsum += data[i]; } if(maxsum) { QPainterPath cumpath; cumpath.moveTo(0,0); for(int i=0 ; i<graph_size; i++) { sum += data[i]; height = (graph_size)*(((double)sum/(double)maxsum)); height = graph_size-(int)(height+0.5); cumpath.lineTo (i, height ); } p->setPen(Qt::red); p->setBrush(Qt::NoBrush); //p->setBrush(Qt::red); p->drawPath(cumpath); } } //draw our thresholding... p->setPen(Qt::black); p->setBrush(QBrush ( QColor(128,128,128,128), Qt::SolidPattern )); QRectF rectangle(0.0, 0.0, minthr, graph_size); p->drawRect(rectangle); QRectF rectangle2(maxthr, 0.0, graph_size-maxthr, graph_size); p->drawRect(rectangle2); p->setBrush(Qt::NoBrush); }
int main(int argc, char *argv[]) { /* sf::RenderWindow app(sf::VideoMode(640, 480), "ECS"); sf::RectangleShape rectangle(sf::Vector2f(50.f, 50.f)); rectangle.setFillColor(sf::Color::Blue); sf::RectangleShape rectangle2(sf::Vector2f(50.f, 50.f)); rectangle2.setFillColor(sf::Color::Red); GameObject objects[2]; DescriptionSystem desc_sys; MovementSystem move_sys; RenderSystem renderer(&app); CollisionSystem collision_sys; DescriptionComponent desc(objects[0].getId()); PositionComponent pos(objects[0].getId()), pos2(objects[1].getId()); VelocityComponent vel(objects[0].getId(), 1.f), vel2(objects[1].getId(), 0.2f, 0.1f); DrawableComponent drawable(objects[0].getId()), drawable2(objects[1].getId()); CollidableComponent c1(objects[0].getId(), rectangle.getGlobalBounds()), c2(objects[1].getId(), rectangle2.getGlobalBounds()); drawable.drawable = &rectangle; drawable2.drawable = &rectangle2; //pos.position.y = 50.f; pos2.position.x = 250.f; pos2.position.y = 20.f; desc_sys.registerComponent("Description"); move_sys.registerComponent("Position"); move_sys.registerComponent("Velocity"); renderer.registerComponent("Drawable"); renderer.registerComponent("Position"); collision_sys.registerComponent("Position"); collision_sys.registerComponent("Collidable"); objects[0].addComponent(&desc); objects[0].addComponent(&pos); objects[0].addComponent(&vel); objects[0].addComponent(&drawable); objects[0].addComponent(&c1); objects[1].addComponent(&vel2); objects[1].addComponent(&drawable2); objects[1].addComponent(&pos2); objects[1].addComponent(&c2); if (desc_sys.canUpdate(objects[0])) desc_sys.update(objects[0]); sf::Event event; while (app.isOpen()) { while (app.pollEvent(event)) { if (event.type == sf::Event::Closed) app.close(); } for (int i(0) ; i < 2 ; ++i) if (move_sys.canUpdate(objects[i])) move_sys.update(objects[i]); app.clear(sf::Color::White); for (int i(0) ; i < 2 ; ++i) if (collision_sys.canUpdate(objects[i])) collision_sys.update(objects[i]); for (int i(0) ; i < 2 ; ++i) if (renderer.canUpdate(objects[i])) renderer.update(objects[i]); app.display(); } */ GameWorld world; GameObject *o1(world.addObject()); GameObject *o2(world.addObject()); sf::RectangleShape rectangle1(sf::Vector2f(50.f, 50.f)); rectangle1.setFillColor(sf::Color::Blue); sf::RectangleShape rectangle2(sf::Vector2f(50.f, 50.f)); rectangle2.setFillColor(sf::Color::Red); PhysicSystem *phys_sys(new PhysicSystem); phys_sys->registerComponent("Physic"); phys_sys->registerComponent("Position"); world.addSystem(phys_sys); PhysicComponent phys1(o1->getId(), 50, cpMomentForBox(50, 5, 5)), phys2(o2->getId(), 50, cpMomentForBox(50, 5, 5)); DescriptionComponent desc1(o1->getId()), desc2(o2->getId()); PositionComponent pos1(o1->getId()), pos2(o2->getId()); //VelocityComponent vel1(objects[0].getId(), 1.f), vel2(objects[1].getId(), 0.2f, 0.1f); DrawableComponent drawable1(o1->getId()), drawable2(o2->getId()); //CollidableComponent c1(objects[0].getId(), rectangle.getGlobalBounds()), c2(objects[1].getId(), rectangle2.getGlobalBounds()); phys1.shape = cpBoxShapeNew(phys1.body, 50.f, 50.f); phys2.shape = cpBoxShapeNew(phys2.body, 50.f, 50.f); cpBodySetPos(phys1.body, cpv(0, 0)); cpBodySetPos(phys2.body, cpv(200, 0)); cpSpaceAddShape(phys_sys->getSpace(), phys1.shape); cpSpaceAddShape(phys_sys->getSpace(), phys2.shape); cpSpaceAddBody(phys_sys->getSpace(), phys1.body); cpSpaceAddBody(phys_sys->getSpace(), phys2.body); drawable1.drawable = &rectangle1; drawable2.drawable = &rectangle2; pos1.position.x = 50.f; pos2.position = sf::Vector2f(200.f, 150.f); o1->addComponent(&desc1); o1->addComponent(&drawable1); o1->addComponent(&pos1); o1->addComponent(&phys1); o2->addComponent(&desc2); o2->addComponent(&drawable2); o2->addComponent(&pos2); o2->addComponent(&phys2); while (true) { world.update(); } return 0; }
int main() { // Read input image cv::Mat image= cv::imread("../images/group.jpg"); if (!image.data) return 0; // Display the image cv::namedWindow("Original Image"); cv::imshow("Original Image",image); // Get the binary map cv::Mat binary; binary= cv::imread("../images/binary.bmp",0); // Display the binary image cv::namedWindow("Binary Image"); cv::imshow("Binary Image",binary); // Eliminate noise and smaller objects cv::Mat fg; cv::erode(binary,fg,cv::Mat(),cv::Point(-1,-1),6); // Display the foreground image cv::namedWindow("Foreground Image"); cv::imshow("Foreground Image",fg); // Identify image pixels without objects cv::Mat bg; cv::dilate(binary,bg,cv::Mat(),cv::Point(-1,-1),6); cv::threshold(bg,bg,1,128,cv::THRESH_BINARY_INV); // Display the background image cv::namedWindow("Background Image"); cv::imshow("Background Image",bg); // Show markers image cv::Mat markers(binary.size(),CV_8U,cv::Scalar(0)); markers= fg+bg; cv::namedWindow("Markers"); cv::imshow("Markers",markers); // Create watershed segmentation object WatershedSegmenter segmenter; // Set markers and process segmenter.setMarkers(markers); segmenter.process(image); // Display segmentation result cv::namedWindow("Segmentation"); cv::imshow("Segmentation",segmenter.getSegmentation()); // Display watersheds cv::namedWindow("Watersheds"); cv::imshow("Watersheds",segmenter.getWatersheds()); // Open another image image= cv::imread("../images/tower.jpg"); if (!image.data) return 0; // Identify background pixels cv::Mat imageMask(image.size(),CV_8U,cv::Scalar(0)); cv::rectangle(imageMask,cv::Point(5,5),cv::Point(image.cols-5,image.rows-5),cv::Scalar(255),3); // Identify foreground pixels (in the middle of the image) cv::rectangle(imageMask,cv::Point(image.cols/2-10,image.rows/2-10), cv::Point(image.cols/2+10,image.rows/2+10),cv::Scalar(1),10); // Set markers and process segmenter.setMarkers(imageMask); segmenter.process(image); // Display the image with markers cv::rectangle(image,cv::Point(5,5),cv::Point(image.cols-5,image.rows-5),cv::Scalar(255,255,255),3); cv::rectangle(image,cv::Point(image.cols/2-10,image.rows/2-10), cv::Point(image.cols/2+10,image.rows/2+10),cv::Scalar(1,1,1),10); cv::namedWindow("Image with marker"); cv::imshow("Image with marker",image); // Display watersheds cv::namedWindow("Watersheds of foreground object"); cv::imshow("Watersheds of foreground object",segmenter.getWatersheds()); // Open another image image= cv::imread("../images/tower.jpg"); // define bounding rectangle cv::Rect rectangle(50,70,image.cols-150,image.rows-180); cv::Mat result; // segmentation result (4 possible values) cv::Mat bgModel,fgModel; // the models (internally used) // GrabCut segmentation cv::grabCut(image, // input image result, // segmentation result rectangle,// rectangle containing foreground bgModel,fgModel, // models 1, // number of iterations cv::GC_INIT_WITH_RECT); // use rectangle // Get the pixels marked as likely foreground cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ); // Generate output image cv::Mat foreground(image.size(),CV_8UC3,cv::Scalar(255,255,255)); image.copyTo(foreground,result); // bg pixels not copied // draw rectangle on original image cv::rectangle(image, rectangle, cv::Scalar(255,255,255),1); cv::namedWindow("Image"); cv::imshow("Image",image); // display result cv::namedWindow("Segmented Image"); cv::imshow("Segmented Image",foreground); // Open another image image= cv::imread("../images/group.jpg"); // define bounding rectangle cv::Rect rectangle2(10,100,380,180); cv::Mat bkgModel,fgrModel; // the models (internally used) // GrabCut segmentation cv::grabCut(image, // input image result, // segmentation result rectangle2,bkgModel,fgrModel,5,cv::GC_INIT_WITH_RECT); // Get the pixels marked as likely foreground // cv::compare(result,cv::GC_PR_FGD,result,cv::CMP_EQ); result= result&1; foreground.create(image.size(),CV_8UC3); foreground.setTo(cv::Scalar(255,255,255)); image.copyTo(foreground,result); // bg pixels not copied // draw rectangle on original image cv::rectangle(image, rectangle2, cv::Scalar(255,255,255),1); cv::namedWindow("Image 2"); cv::imshow("Image 2",image); // display result cv::namedWindow("Foreground objects"); cv::imshow("Foreground objects",foreground); cv::waitKey(); return 0; }