// 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 */ // compile command // cl /EHsc part1AFirst.cpp /I D:\installs\opencv\opencv\build\include /link /LIBPATH:D:\installs\opencv\opencv\build\x64\vc15\lib opencv_world451.lib /* imshow("window", dummy); waitKey(0); destroyWindow("window"); */ 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("input1a1.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("brownWalls.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] = 60; frame.at(Point(i, j))[1] = 78; frame.at(Point(i, j))[2] = 115; } } } } } output_cap.write(frame); } // free the capture objects from memory input_cap.release(); output_cap.release(); return 1; }