Example #1
0
 void testScale() {
     report(0,"checking scaling...");
     ImageOf<PixelRgb> img;
     ImageOf<PixelMono> img2;
     ImageOf<PixelRgb> img3;
     img.resize(64,64);
     img.zero();
     for (int i=0; i<img.width()/2; i++) {
         for (int j=0; j<img.height()/2; j++) {
             img(i,j).r = 255;
             img(i,j).g = 255;
             img(i,j).b = 255;
         }
     }
     img2.copy(img,32,32);
     checkEqual(img2.width(),32,"dimension check");
     checkEqual(img2(0,0),255,"logic check");
     checkEqual(img2(img2.width()-2,0),0,"logic check");
     checkEqual(img2(0,img2.height()-2),0,"logic check");
     img3.copy(img,16,16);
     checkEqual(img3.width(),16,"dimension check");
     checkEqual(img3(0,0).r,255,"logic check");
     checkEqual(img3(img3.width()-2,0).r,0,"logic check");
     checkEqual(img3(0,img3.height()-2).r,0,"logic check");
     img.copy(img3,4,4);
     checkEqual(img.width(),4,"dimension check");
 }
Example #2
0
bool OpenCVGrabber::getImage(ImageOf<PixelRgb> & image) {

    // Must have a capture object
    if (!m_cap.isOpened()) {
        image.zero();
        return false;
    }

    // Grab and retrieve a frame
    cv::Mat frame;
    m_cap.read(frame);

    if (frame.empty() && m_loop) {
        bool ok = open(m_config);
        if (!ok) return false;
        m_cap.read(frame);
    }

    if (frame.empty()) {
        image.zero();
        return false;
    }

    if (m_transpose)
    {
        cv::transpose(frame, frame);
    }

    if (m_flip_x && m_flip_y)
    {
        cv::flip(frame, frame, -1);
    }
    else if (m_flip_x)
    {
        cv::flip(frame, frame, 0);
    }
    else if (m_flip_y)
    {
        cv::flip(frame, frame, 1);
    }

    return sendImage(frame, image);
}
Example #3
0
 virtual void run() {
     printf("Fake framegrabber starting\n");
     while (!isStopping()) {
         ImageOf<PixelRgb> img;
         img.resize(40,20);
         img.zero();
         printf("Fake framegrabber wrote an image...\n");
         p.write(img);
         Time::delay(1);
     }
     printf("Fake framegrabber stopping\n");
 }
Example #4
0
 void testDraw() {
     report(0,"checking draw tools...");
     ImageOf<PixelRgb> img;
     img.resize(64,64);
     img.zero();
     addCircle(img,PixelRgb(255,0,0),32,32,200);
     // full image should be colored blue
     bool ok = true;
     IMGFOR(img,x,y) {
         if (img.pixel(x,y).r!=255) {
             ok = false;
         }
     }
     checkTrue(ok,"image is blue");
 }
Example #5
0
 void testStandard() {
     report(0,"checking standard compliance of description...");
     ImageOf<PixelRgb> img;
     img.resize(8,4);
     img.zero();
     BufferedConnectionWriter writer;
     img.write(writer);
     ConstString s = writer.toString();
     Bottle bot;
     bot.fromBinary(s.c_str(),s.length());
     checkEqual(bot.size(),4,"plausible bottle out");
     checkEqual(bot.get(0).toString().c_str(),"mat","good tag");
     YARP_DEBUG(Logger::get(),"an example image:");
     YARP_DEBUG(Logger::get(),bot.toString().c_str());
 }
Example #6
0
bool OpenCVGrabber::getImage(ImageOf<PixelRgb> & image) {

    //yTrace("-->getImage123");

    // Must have a capture object
    if (0 == m_capture) {
        image.zero(); return false;
    }

    //yTrace("-->HERE1");
    // Grab and retrieve a frame, OpenCV owns the returned image
    IplImage * iplFrame = cvQueryFrame((CvCapture*)m_capture);
    //yTrace("-->HERE2");

    if (0 == iplFrame && m_loop) {
        bool ok = open(m_config);
        if (!ok) return false;
        iplFrame = cvQueryFrame((CvCapture*)m_capture);
    }

    if (0 == iplFrame) {
        image.zero(); return false;
    }
    
    if (m_transpose == false && m_flip_x == false && m_flip_y == false)
    {
        return sendImage(iplFrame, image);
    }

    IplImage * iplFrame_out;
    if (m_transpose)
    {
        iplFrame_out = cvCreateImage(cvSize(iplFrame->height, iplFrame->width), iplFrame->depth, iplFrame->nChannels);
        cvTranspose(iplFrame, iplFrame_out);
    }
    else
    {
        iplFrame_out = cvCreateImage(cvSize(iplFrame->width, iplFrame->height), iplFrame->depth, iplFrame->nChannels);
        cvCopy(iplFrame, iplFrame_out);
    }

    if (m_flip_x && m_flip_y)
    {
        cvFlip(iplFrame_out, 0, -1);
    }
    else
    {
        if (m_flip_x)
        {
            cvFlip(iplFrame_out, 0, 0);
        }
        else if (m_flip_y)
        {
            cvFlip(iplFrame_out, 0, 1);
        }
    }
    bool ret = sendImage(iplFrame_out, image);
    cvReleaseImage(&iplFrame_out);

    return ret;
}