0

OpenCV を使用してプログラムのビデオ キャプチャに画像を重ねようとしていますが、うまく動作しません。Web カメラから取得した元のフレームに関心領域を長方形の形で設定します。次に、元のフレームにコピーします。ただし、Web カメラによってキャプチャされた新しいフレームには表示されません。テストしたところ、画像は正しく読み込まれていますが、何らかの理由で新しいフレームにコピーされていません。

以下の C++ のコード:

#include<opencv2/core/core.hpp>
#include<opencv2/contrib/contrib.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<vector>

using namespace std;
using namespace cv;

int main(){
    VideoCapture cap;
    cap.open(0);

    if(!cap.isOpened()){
        cerr << "Error opening the webcam!" << endl;
        return -1;
    }


    for(;;){
        Mat frame;

        cap>>frame; 

        Mat newFrame;
        frame.copyTo(newFrame);

        Mat image = imread("C:\\User\\Desktop\\images\\image.png");


    int cx = (newFrame.cols - 70) / 2;
        if (image.data) {
            // Get a BGR version of the face, since the output is BGR color
            Mat srcBGR = Mat(face.size(), CV_8UC3);
            cvtColor(image, srcBGR, CV_GRAY2BGR);
            // Get the destination ROI (and make sure it is within the image)
            Rect dstRC = Rect(cx, newFrame.rows/2, 70, 70);
            Mat dstROI = newFrame(dstRC);
            // Copy the pixels from src to dst.
            srcBGR.copyTo(dstROI);
        }


        imshow("frame", newFrame);
        char key = (char) waitKey(30);
        // Exit this loop on escape:
        if(key == 27)
            break;
    }   

    return 0;
}

提案や助けをいただければ幸いです。ありがとう。

4

1 に答える 1