我想告诉你视频机器人的方式 . 我需要检测每个机器人的颜色,更改像素,例如,黑色和每个帧,放大黑色区域以显示机器人覆盖的整个表面 .

我怎样才能做到这一点?用什么?我使用了移动平均线,但它并没有导致单个像素颜色的不断变化 .

如何使机器人路径绘制?

这是我的视频:MyVideo

这是我的代码:

使用命名空间cv; using namespace std;

string intToString(int number){

std::stringstream ss;
ss << number;
return ss.str();

}

int main(int argc,char * argv []){

bool recording = false;
bool startNewRecording = false;
int inc = 0;
bool firstRun = true;

VideoCapture cap("F:/WAŻNE/Praca magisterska/Projekt pokrycie powierzchni/pokrycie powierzchni2/Data/44.mp4");
VideoWriter oVideoWriter;//create videoWriter object, not initialized yet

if (!cap.isOpened())  // if not success, exit program
{
    cout << "ERROR: Cannot open the video file" << endl;
    return -1;
}

namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

//set framesize for use with videoWriter
Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));


for (;;) {
    Mat frame;

    bool bSuccess = cap.read(frame); // read a new frame from video
    cap >> frame; // get a new frame from camera


                  //Analiza obrazu, i wpisanie elementow obrazu do macierzy pozycji
    for (int i = 0; i < frame.rows; i++) {
        // Podział obrazu na czesci, jesli w wyznaczonej czesci znaleziono ktorys z kolorow robotow to przyporzadkowanie kolejno warto 2,3,4 w macierzy pozycji
        for (int j = 0; j < frame.cols; j++) {
            if (frame.at<Vec3b>(i, j)[0] >= 192 && frame.at<Vec3b>(i, j)[1] <= 130 && frame.at<Vec3b>(i, j)[2] <= 100) {
                frame.at<Vec3b>(i, j)[0] = 255;
                frame.at<Vec3b>(i, j)[1] = 255;
                frame.at<Vec3b>(i, j)[2] = 255;
                break;
            }
            if (frame.at<Vec3b>(i, j)[1] >= 150 && frame.at<Vec3b>(i, j)[0] <= 130 && frame.at<Vec3b>(i, j)[2] <= 100) {
                frame.at<Vec3b>(i, j)[0] = 255;
                frame.at<Vec3b>(i, j)[1] = 255;
                frame.at<Vec3b>(i, j)[2] = 255;
                break;
            }
            if (frame.at<Vec3b>(i, j)[2] >= 160 && frame.at<Vec3b>(i, j)[0] <= 130 && frame.at<Vec3b>(i, j)[1] <= 80) {
                frame.at<Vec3b>(i, j)[0] = 255;
                frame.at<Vec3b>(i, j)[1] = 255;
                frame.at<Vec3b>(i, j)[2] = 255;
                break;
            }

        }
    }



    if (!bSuccess) //if not success, break loop
    {
        cout << "ERROR: Cannot read a frame from video file" << endl;
        break;
    }
    if (startNewRecording == true) {


        oVideoWriter = VideoWriter("F:/WAŻNE/Praca magisterska/Projekt pokrycie powierzchni/pokrycie powierzchni2/Data/output.avi" + intToString(inc) + ".avi", CV_FOURCC('D', 'I', 'V', '3'), 20, frameSize, true); //initialize the VideoWriter object 
        recording = true;
        startNewRecording = false;
        cout << "New video file created F:/MyVideo" + intToString(inc) + ".avi " << endl;


        if (!oVideoWriter.isOpened()) //if not initialize the VideoWriter successfully, exit the program
        {
            cout << "ERROR: Failed to initialize video writing" << endl;
            getchar();
            return -1;
        }

    }
    //if we're in recording mode, write to file
    if (recording) {

        oVideoWriter.write(frame);
        //show "REC" in top left corner in red
        //be sure to do this AFTER you write to the file so that "REC" doesn't show up
        //on the recorded video.
        putText(frame, "REC", Point(0, 60), 2, 2, Scalar(0, 0, 255), 2);


    }
    imshow("MyVideo", frame); //show the frame in "MyVideo" window
                              //    imshow("edges", edges);

    switch (waitKey(10)) {

    case 114:
        //'r' has been pressed.
        //toggle recording mode
        recording = !recording;

        if (firstRun == true) {

            cout << "New Recording Started" << endl;
            oVideoWriter = VideoWriter("F:/WAŻNE/Praca magisterska/Projekt pokrycie powierzchni/pokrycie powierzchni2/Data/output.avi", CV_FOURCC('D', 'I', 'V', '3'), 20, frameSize, true);

            if (!oVideoWriter.isOpened())
            {
                cout << "ERROR: Failed to initialize video writing" << endl;
                getchar();
                return -1;
            }
            firstRun = false;


        }
        else {
            if (!recording)cout << "Recording Stopped" << endl;

            else cout << "Recording Started" << endl;
        }
        break;

    case 110:
        //'n' has been pressed
        //start new video file
        startNewRecording = true;
        cout << "New Recording Started" << endl;
        //increment video file name
        inc += 1;
        break;
    case 27:
        //'esc' has been pressed
        //exit program.
        cout << "Exit Program" << endl;
        return 0;



    }


}

return 0;

}}