Saving kinect depth Map to video stream

I have a kinect depth image that I’m displaying in of with an ofImage defined in setup as

ofDepthImg.allocate(kinect.width, kinect.height, OF_IMAGE_COLOR);

I’m trying to record the colour and depth images so I can make some test videos to work with without constantly standing in front of the kinect. I can record the colour video stream fine using ofxVideoRecorder. However when I try to record the depth map even though the image I’m putting it in is defined as type OF_IMAGE_COLOR with 3 channels the video stream is messed up and I get 9 copies of the the depth map recorded in the video file.

`        //read in depth image
        depthImg = cv::Mat(kinect.height, kinect.width, CV_8UC1, kinect.getDepthPixels(), 0);
        
        //convert to of format for display and recording
        toOf(depthImg, ofDepthImg);
        ofDepthImg.update();
        
        //record depth image
        if (bRecording) {
            bool success = vidRecorder2.addFrame(ofDepthImg.getPixels());
            if (!success) {
                ofLogWarning("This frame was not added");
            }
        }`

How do I force the grayscale depth map to record correctly?

cvtColor was the answer

`//read in depth image
depthImg = cv::Mat(kinect.height, kinect.width, CV_8UC1, kinect.getDepthPixels(), 0);

    //force 3 channel copy for display and recording
    cv::Mat bgr;
    cv::cvtColor(depthImg, bgr, CV_GRAY2BGR);
    
    //convert to of format for display and recording
    toOf(bgr, ofDepthImg);
    
    ofDepthImg.update();
    
    //record depth image
    if (bRecording) {
        
        bool success = vidRecorder2.addFrame(ofDepthImg.getPixels());
        if (!success) {
            ofLogWarning("This frame was not added");
        }
    }`