function out = mat2ocv(img)
    % Convert image data format to OpenCV compatible format
    %
    % Copyright 2018 The MathWorks, Inc.
    sz = size(img);
    Iocv = zeros([prod(sz), 1], 'uint8');
    % Reshape input data
    Ir = permute(img, [2 1 3]);
    % RRR...GGG...(MATLAB) format to BGRBGR...(openCV) format
    Iocv(1:3:end) = Ir(:,:,3);
    Iocv(2:3:end) = Ir(:,:,2);
    Iocv(3:3:end) = Ir(:,:,1);
    % Reshape Matrix
    out = reshape(Iocv, sz);
end