Module src.processing.cam_control
Module for manipulating images as if it was a camera
Classes
class CamController (res: Tuple[int, int] = (1920, 1080))-
Keeps a state for the current camera settings (zoom, center, exposure) uses this to process frames.
Zoom, pan and set_gamma changes fields in the object but return nothing. The process function is then used to process the image with the current settings. It is set up this way to support multiple hands controlling the camera at once.
Multiple calls to zoom and pan can be done on each input frame. But the image buffer will only be manipulated once.
Args
res- Resolution of frames, tuple of (x, y)
Methods
def process(self, frame: numpy.ndarray) ‑> numpy.ndarray-
Processes the frame with the current object settings.
First crops the frame to the current zoom and center values. Then applies gamma correction to the cropped image. If these values have not been altered since object instantiation, the corresponding functions will have no effect.
Args
frame- Image buffer
Returns
Cropped, translated and gamma corrected image buffer.
def interpolate_zoom(self, zoom: float) ‑> float-
Interpolates zoom values with bezier
Args
Zoom- zoom value, [-1, 1], -1 and 1 being zooming out or in at max speed respectively
Returns
Difference in zoom in respect to current zoom
def zoom(self, zoom: float, smoothing: bool = True) ‑> NoneType-
Zooms in or out on center of frame
Adds zoom input to the zoom field and changes the size field accordingly. Size is essentially width and height of frame after crop
Args
zoom- signed float representing zoom percent and direction
smoothing- whether to interpolate zoom values with bezier or not
def pan(self, pos: Tuple[float, float]) ‑> NoneType-
Translates cropped frame
Scales position in landmark space to image dimensions and moves the center field to that point. Effectively translating cropped image on the input image.
Args
pos- position in landmark space
def hand_framed_crop(self, multi_landmarks: Tuple[Iterable[mediapipe.framework.formats.landmark_pb2.NormalizedLandmark], Iterable[mediapipe.framework.formats.landmark_pb2.NormalizedLandmark]]) ‑> NoneType-
Zooms in on region enclosed by two hands
Creates a corner point in the intersection between index and thumb for the first two hand_landmarks in multi_landmarks. Sets self.center and self.size to fit the to fit the resulting rectangle.
Args
multi_landmarks- tuple containing two hands landmarks
def set_gamma(self, normalized_gamma: float) ‑> NoneType-
Sets self._gamma from a normalized value.
Takes in a normalized value. If the value is below 0.5, gamma is set to 1 / c, else it is set to c. c has range [1.0 self.gamma_max] and is given by the linear function c(x) = 1 + (x * (\gamma_{max} - 1)) where x is the absolute value of normalized_gamma shifted by -0.5, and \gamma_{max} = self.gamma_max
Args
normalized_gamma- A normalized representation ([0.0, 1.0]) of the intended gamma value.