When cv2.imwirte() saves ".gif", it will cause _error: (-2:Unspecified error) could not find a writer for the specified extension in function 'cv::imwrite_'_. We add an if statement to check whether the saving file format is ".gif" so as to avoid the error.