OpenCV 2.3: Convert Mat to RGBA pixel array

前端 未结 3 1562
一向
一向 2020-12-10 07:23

I am attempting to use OpenCV to grab frames from a webcam and display them in a window using SFML.

VideoCapture returns frames in OpenCV\'s Mat format. To display t

3条回答
  •  轮回少年
    2020-12-10 07:55

    OpenCV can do all job for you:

    VideoCapture cap(0);
    Mat frame;
    cap >> frame;
    
    uchar* camData = new uchar[frame.total()*4];
    Mat continuousRGBA(frame.size(), CV_8UC4, camData);
    cv::cvtColor(frame, continuousRGBA, CV_BGR2RGBA, 4);
    img.LoadFromPixels(frame.cols, frame.rows, camData);
    

提交回复
热议问题