August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
This component applies a crop and/or scaling operation to frames of RGB video.
Requires PIL - the python imaging library.
Crop and scale a YUV4MPEG format uncompressed video file so that the output is the region (100,100) ->(400,300), scaled up to 720x576:
from Kamaelia.File.Reading import RateControlledFileReader
Pipeline( RateControlledFileReader("input.yuv4mpeg", ... ),
YUV4MPEGToFrame(),
ToRGB_interleaved(),
CropAndScale(newsize=(720,576), cropbounds=(100,100,400,300)),
ToYUV420_planar(),
FrameToYUV4MPEG(),
SimpleFileWriter("cropped_and_scaled.yuv4mpeg"),
).run()
Initialise this component specifying the region of the incoming video frames to crop to, and the size of the desired output (the cropped region will be scaled up/down to match this).
Send frame data structures to the "inbox" inbox of this component. The frames will be cropped and scaled and output from the "outbox" outbox. Only frames with one of the following pixel formats are currently supported:
"RGB_interleaved" "RGBA_interleaved" "Y_planar"
See below for a description of the uncompressed frame data structure format. Send uncompressed video frames, in the format described below,
This component supports sending data out of its outbox to a size limited inbox. If the size limited inbox is full, this component will pause until it is able to send out the data. Data will not be consumed from the inbox if this component is waiting to send to the outbox.
If a producerFinished message is received on the "control" inbox, this component will complete parsing any data pending in its inbox, and finish sending any resulting data to its outbox. It will then send the producerFinished message on out of its "signal" outbox and terminate.
If a shutdownMicroprocess message is received on the "control" inbox, this component will immediately send it on out of its "signal" outbox and immediately terminate. It will not complete processing, or sending on any pending data.
A frame is a dictionary data structure, containing at minimum one of these combinations:
{
"yuv" : luminance_data
"pixformat" : pixelformat # format of raw video data
"size" : (width, height) # in pixels
}
{
"rgb" : rgb_interleaved_data
"pixformat" : pixelformat # format of raw video data
"size" : (width, height) # in pixels
}
CropAndScale only guarantees to fill in the fields above. Any other fields will be transparently passed through, unmodified.
CropAndScale(newsize, cropbounds) -> new CropAndScale component.
Crops and scales frames of video in RGB format.
Keyword arguments:
Warning!
You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT