Capture Mat copy to UMat fails on 32-bit app, works on 64-bit, timing?

asked 2016-01-23 00:36:50 -0500

updated 2016-01-23 01:20:52 -0500

berak gravatar image

Here's a interesting problem with OpenCV 3.1.0, this code fails with an cv:Exception in clEnqueue on a 32 bit build, and yes per MSVC Diagnoctics it grows to 2GB and fails. Same code/32bit-build with imshow/waitkey then no exception. On 64bit the mem usage goes up to 2GB but then drops back down, then goes back up! What is going on? Remove the im.copyTo the UMat then no memory leak... Weird.

#include "stdafx.h"
#include "opencv2\core.hpp"
#include "opencv2\core\ocl.hpp"
#include "opencv2\videoio.hpp"
#include "opencv2\highgui.hpp"
#include <queue>
#include <thread>
#include <conio.h>
#include <stdexcept>
#include <iostream>

using namespace std;
using namespace cv;
void SetupOpenCL(bool);

int main(int argc, char **argv)
    VideoCapture capture;
    string videoin = "c:\\file.avi";;
    if (capture.isOpened())
        cout << "opened capture";
        std::cout << "failed to open capture device or filename";

    SetupOpenCL(true); // bEnableOpenCL);

    while (1)
        Mat im;
        UMat uim = im.getUMat(ACCESS_RW);

        if (uim.empty()) break;

        int frameNumber = static_cast<int>(capture.get(CAP_PROP_POS_FRAMES));
        std::cout << "frame:" << frameNumber << endl;

        //imshow("uim", uim);
    if (capture.isOpened())

void SetupOpenCL(bool enable)
    bool hocl = cv::ocl::haveOpenCL();
    if (enable && !hocl)
    bool uocl = cv::ocl::useOpenCL();
edit retag flag offensive close merge delete