Splitting a frame into a grid and combining again (c++, 2.4.11)

asked 2017-03-10 11:30:09 -0600

updated 2018-10-26 16:11:44 -0600

Hi, new to this forum and new to OpenCV.

I'm using version 2.4.11, with Eclipse Neon C++

This is for a university assignment and is only the first step, main part of the assignment is scrambling the grid and applying different effects to them.

My problem is the webcam feed will not stay open for more than a split second, if I use waitKey(0) it will display a single frame but any other way and it just instantly closes, if anyone could help me get this working I'd be really grateful

    Mat frame, img_gry, img_gry_color;
    int a = 0;
    Mat imagesmall[100];
    vector<Mat> img_gry_vec;
    cv::Size sb_size(64,48);
    for(;;) {
        cap >> frame;
        if ( frame.empty()) {

            break;
        }
          for  ( int y = 0; y < 480; y += sb_size.height )

          {
            for  ( int  x= 0 ; x < 640; x += sb_size.width )
            {
                imagesmall[a] = Mat(frame, Rect(x,y,(sb_size.width), (sb_size.height))).clone();
                img_gry_vec.push_back(imagesmall[a]);
                a++;
            }
          }
        cv::Mat combined(480,640, img_gry_vec[0].type());
        a = 0;
          for  ( int y = 0; y < 480; y += sb_size.height )
          {
            for  ( int  x= 0 ; x < 640; x += sb_size.width )
            {
                  cv::Mat roi = combined(cv::Rect(x,y,sb_size.width,sb_size.height));
                  img_gry_vec[a].copyTo(roi);
                  a++;
            }
          }
        cv::imshow("combined" , combined);

        img_gry_vec.clear();
        if ( cv::waitKey(33) >= 0)
                        break;


    }

    return 0;
edit retag flag offensive close merge delete

Comments

press ESC to quit :

   if ( cv::waitKey(33)==27)
                    break;
LBerger gravatar imageLBerger ( 2017-03-10 11:58:39 -0600 )edit