In this tutorial, I will show you how to add image effects to the Raspberry Pi camera module by creating a class in Python, which lets you define annotation text, framerate, resolution, and filename.
The image effect options are(1):
Note: The default effect is none.
- Include the required libraries.
- Create a class named camera_effects.
- Define the camera module settings - resolution and framerate - in the __init__() function.
- In the record() function, define the video file path and location and record a video with the given settings - filename, annotate, and effect.
- Define a new class object named as video.
- Enter the filename, annotation text, and select an image effect to apply from the list above.
-------------- Python -------------- from picamera import PiCamera from time import sleep class camera_effects: def __init__(self, r_x, r_y, framerate): # Define the camera module settings. self.camera = PiCamera() self.camera.resolution = (r_x, r_y) self.camera.framerate = framerate def record(self, filename, annotate, effect): # Define video file path and location. path = '/home/pi/' + filename # Record a video with the given settings. self.camera.annotate_text = annotate self.camera.image_effect = effect self.camera.start_preview() self.camera.start_recording() sleep(30) self.camera.stop_recording() self.camera.stop_preview() print("Rasp_Pi => Video Recorded! \r\n") # Define a new class object named as 'video'. video = camera_effects(800, 600, 30) #Record a video with the selected camera effect: #"none" #"negative" #"solarize" #"sketch" #"pastel" #"watercolor" #"film" #"blur" #"saturation" #"posterise" #"cartoon" #"colorpoint" #"colorbalance" # ... video.record('test.h264', 'Testing Effects', 'negative')
You can inspect my electronics project in which the mentioned method is used to develop a video recoder and uploader GUI allowing the user to implement image effects on the interface from here.