// Headers #include #include #include #include #include using namespace cv; /* blue outline RGB = 38, 41, 124 pacman RGB = 255, 234, 4 power pellet = 255, 181, 187 pips = 200, 195, 185 red ghost = 255, 24, 2 purple ghost = 246, 195, 248 orange ghost = 244, 179, 68 blue ghost = 0, 223, 251 words = 223, 221, 227 */ int main(int argc, char* argv[]) { // Load input video // If your video is in a different source folder than your code, // make sure you specify the directory correctly! VideoCapture input_cap("input1a2.avi"); // Check validity of target file if(!input_cap.isOpened()) { std::cout << "Input video not found." << std::endl; return -1; } // Set up target output video /* usage: VideoWriter(filename, encoding, framerate, Size) * in our case, cv_cap_prop_* means "get property of capture" * we want our output to have the same properties as the input! */ VideoWriter output_cap("greenWalls.avi", input_cap.get(CAP_PROP_FOURCC), input_cap.get(CAP_PROP_FPS), Size(input_cap.get(CAP_PROP_FRAME_WIDTH), input_cap.get(CAP_PROP_FRAME_HEIGHT))); // Again, check validity of target output file if(!output_cap.isOpened()) { std::cout << "Could not create output file." << std::endl; return -1; } // Loop to read from input one frame at a time, write text on frame, and // copy to output video Mat frame; while(input_cap.read(frame)) { for(int i = 0; i < frame.cols; i++){ for(int j = 0; j < frame.rows; j++){ int blueChan = frame.at(Point(i, j))[0]; int greenChan = frame.at(Point(i, j))[1]; int redChan = frame.at(Point(i, j))[2]; if(blueChan >= 64 && blueChan <= 184){ if(greenChan >= 0 && greenChan <= 101){ if(redChan >= 0 && redChan <= 98){ frame.at(Point(i, j))[0] = 0; frame.at(Point(i, j))[1] = 255; frame.at(Point(i, j))[2] = 0; } } } } } output_cap.write(frame); } // free the capture objects from memory input_cap.release(); output_cap.release(); return 1; }