- Home
- Installation
- Using Livekeys
- Plugins
- Developer
Plugin lcvcore
This module contains all the main qml elements for Livekeys's computer vision code. In comparison to opencv, it is an actual merge between the core and highgui modules.
import lcvcore 1.0
Summary
Type Mat | Main matrix object with variable types. |
Type WritableMat | Writable matrix object, used mostly for quick operations like drawing |
Type MatOp | Singleton type for matrix operations. |
Type MatView | Displays a Mat as an image. |
Type ImRead | Read an image from the hard drive into a lcvcore.Mat structure. |
Type ImWrite | Saves an image to a specified file. |
Type MatDisplay | Simple matrix display element. |
Type MatDisplay | Simple matrix display element. |
Type MatFilter | Base filter for processing images. |
Type MatRoi | Selects a region of interest (ROI) |
Type MatRead | Displays a matrixes values in text form |
Type MatBuffer | Keeps the previous frame. |
Type CamCapture | Captures frames from a connected camera. This is a static item. |
Type VideoCapture | Captures frames from video files.This is a static item. |
Type AlphaMerge | Merges an alpha channel to a matrix. |
Type AbsDiff | Performs an absolute difference between two matrixes. |
Type ImageFile | Read an image from the hard drive into a Mat structure. |
Type OverlapMat | Overlaps 2 matrixes |
Type ItemCapture | Captures the screen into a Mat object. |
Type VideoControls | Video controls provides a play/pause button and a seekbar for VideoCapture |
Type VideoWriter | Writes video to a file. This is a static item. |
Type DrawHistogram | Draws a histogram given from a set of points |
Type ColorHistogram | Calculates histogram for a given matrix |
Mat
type
Inherits | Shared |
Enum | Type |
Method | ByteArray buffer() |
Method | int channels() |
Method | int depth() |
Method | size dimensions() |
Method | Mat cloneMat() |
Method | Mat createOwnedObject() |
Main matrix object with variable types.
You can access a matrix's pixels from QML by using the buffer() function, which gives you a js ArrayBuffer. Here's a how you can access pixel values from a RGB matrix.
ImRead{
id : src
file : project.path + '/sample.jpg'
Component.onCompleted : {
var buffer = output.buffer()
var size = output.dimensions()
var channels = output.channels()
var bufferview = new Uint8Array(buffer)
for ( var i = 0; i < size.height; ++i ){
for ( var j = 0; j < size.width; ++j ){
var b = bufferview[i * size.width + j * channels + 0]; // get the blue channel
var g = bufferview[i * size.width + j * channels + 1]; // get the green channel
var r = bufferview[i * size.width + j * channels + 2]; // get the red channel
}
}
}
}
A sample on accessing and changing matrixes is available in samples/core/customfilter.qml :
Type
enum
Matrix type.
The matrix can be one of the following:
Mat.CV8U
Mat.CV8S
Mat.CV16U
Mat.CV16S
Mat.CV32S
Mat.CV32F
Mat.CV64F
ByteArray buffer()
method
Returns an equivalent ArrayBuffer to access the matrix values
int channels()
method
Returns the number of channels for the matrix
int depth()
method
Returns the depth or type of the matrix
size dimensions()
method
Returns the matrix dimensions
Mat cloneMat()
method
Returns a cloned matrix with javascript ownership
Mat createOwnedObject()
method
Returns a shallow copied matrix with javascript ownership
WritableMat
type
Inherits | Shared |
Method | ByteArray buffer() |
Method | int channels() |
Method | int depth() |
Method | size dimensions() |
Method | Mat toMat() |
Writable matrix object, used mostly for quick operations like drawing
ByteArray buffer()
method
Returns an equivalent ArrayBuffer to access the matrix values
int channels()
method
Returns the number of channels for the matrix
int depth()
method
Returns the depth or type of the matrix
size dimensions()
method
Returns the matrix dimensions
Mat toMat()
method
Returns a Mat object copy of the WritableMat.
MatOp
type
Inherits | QtObject |
Singleton type for matrix operations.
Main object used to create matrices and manage simple operations on them.
Creation examples:
import QtQuick 2.3
import lcvcore 1.0 as Cv
Grid{
spacing: 2
Cv.MatView{
mat: {
var m = Cv.MatOp.create(Qt.size(100, 100), Cv.Mat.CV8U, 3)
Cv.MatOp.fill(m, "#003333")
return m
}
}
Cv.MatView{
mat: Cv.MatOp.createFill(Qt.size(100, 100), Cv.Mat.CV8U, 3, "#660000")
}
Cv.MatView{
mat: Cv.MatOp.createFromArray([
[0, 100, 0],
[150, 0, 250],
[0, 200, 0]
])
linearFilter: false
width: 100
height: 100
}
}
Mat create(size size, Mat.Type type = Mat.CV8U, int channels = 1)
method
Creates a matrix given the size, type and number of channels.
Mat createFill(size size, Mat.Type type = Mat.CV8U, int channels, color color)
method
Creates a matrix given the size, type and number of channels, and fills it with the specified color.
Mat createFromArray(Array a, Mat.Type type = Mat.CV8U)
method
Creates a matrix given a 2 dimensional array.
fill(Mat m, color color)
method
Fills a matrix with the given color.
fillWithMask(Mat m, color color, Mat mask)
method
Fills a matrix with the given color within the region of the binary mask.
Mat crop(Mat m, rect region)
method
Crops a matrix by the specified region.
Matrix4x4 to4x4Matrix(Mat m)
method
Returns a Matrix4x4 qml element from a given matrix m
. m
is required to be a 4x4
matrix.
Array toArray(Mat m)
method
Returns the matrix m
as a js Array.
MatView
type
Inherits | Item |
Property | Mat mat |
Property | bool linearFilter |
Displays a Mat as an image.
Mat mat
property
The matrix to be displayed.
bool linearFilter
property
Smooths the displayed image through linear filtering. Default is true
.
ImRead
type
Inherits | MatDisplay |
Property | string file |
Property | ImRead.Load isColor |
Read an image from the hard drive into a lcvcore.Mat structure.
To read the image, all you need is to specify the location :
ImRead{
file : 'sample.jpg'
}
You can load the image from the location where your qml file is saved by using the path from the project
variable.
ImRead{
file : project.dir() + '/../../../samples/_images/caltech_buildings_DSCN0246.JPG'
}
string file
property
The path to the file to load.
ImRead.Load isColor
property
Color type of the image
Can be one of the following:
ImRead.CV_LOAD_IMAGE_UNCHANGED
ImRead.CV_LOAD_IMAGE_GRAYSCALE
ImRead.CV_LOAD_IMAGE_COLOR
ImRead.CV_LOAD_IMAGE_ANYDEPTH
ImRead.CV_LOAD_IMAGE_ANYCOLOR
ImWrite
type
Inherits | QtObject |
Property | Object params |
Saves an image to a specified file.
Object params
property
Parameters can be one of the following, also dependent on the format the image is saved in:
{
'jpegQuality' : // jpeg compression
'pngCompression' : // png compression
'pxmBinary' : // For PPM, PGM, or PBM, it can be a binary format flag ( CV_IMWRITE_PXM_BINARY ), 0 or 1. Default value is 1.
}
MatDisplay
type
Inherits | Item |
Method | saveImage(string file, Mat image) |
Inherits | Item |
Property | Mat MatDisplay output |
Property | bool MatDisplay linearFilter |
Simple matrix display element.
This type serves as a base for all other livekeys types that require displaying a matrix, which is available in its output property. You can choose wether smoothing occurs when scaling the image for display by enabling linear
saveImage(string file, Mat image)
method
Save the image
to a file
path.
MatDisplay
type
Inherits | Item |
Method | saveImage(string file, Mat image) |
Inherits | Item |
Property | Mat MatDisplay output |
Property | bool MatDisplay linearFilter |
Simple matrix display element.
This type serves as a base for all other types that want to display a matrix, exposed in its
output
property. You can choose wether smoothing occurs when scaling the image by enabling linear
filtering.
Mat MatDisplay output
property
This property holds the output element to display on screen.
bool MatDisplay linearFilter
property
If set to true
, linear filtering will occur when scaling the image on the screen. Default value is true
.
MatFilter
type
Inherits | MatDisplay |
Property | Mat input |
Base filter for processing images.
Inherits the MatDisplay
type in order to display a Mat
through it's output
property, which is the result of
processing the input
. This class doesn't have any processing implemented, however it serves as a base type for most
transformations within lcv plugins.
Mat input
property
Input matrix to apply the filter to.
MatRoi
type
Inherits | MatFilter |
Property | int regionX |
Property | int regionY |
Property | int regionWidth |
Property | int regionHeight |
Selects a region of interest (ROI)
Selects a region from an image for further processing. The 'PanAndZoom' component shows how to use a MatRoi to select a region from an image, then use a MatRead to read the regions values.
See samples/imgproc/panandzoom.qml
int regionX
property
The x coordinate of the most top-left point of the region.
int regionY
property
The y coordinate of the most top-left point of the region.
int regionWidth
property
The width of the seleted region.
int regionHeight
property
The height of the seleted region.
MatRead
type
Inherits | Item |
Property | int input |
Property | Font font |
Property | Color color |
Property | int numberWidth |
Property | bool squareCell |
Displays a matrixes values in text form
Reads an image's values and displays them on the screen in the form of a grid. See the PanAndZoom
component for more
details.
See samples/imgproc/panandzoom.qml
An alternative to the given example is to use a flickable area and use the MatRead
over a whole image.
int input
property
Input matrix to read.
Font font
property
Font to use when displaying values. Default is "Courier New" with 12 pixel size.
Color color
property
Color of the displayed values
int numberWidth
property
Number of digits to display for each number. Default is 3.
bool squareCell
property
When enabled, each number cell will be resized to a square shape. This is useful if you want to display pixels together with their values. Default is false.
MatBuffer
type
Inherits | MatDisplay |
Property | Mat input |
Keeps the previous frame.
The MatBuffer type is useful when it comes to video playback and you need to keep reference to a previous frame. The buffer stores the frame for next usage, so by it's output you actually get the last frame that was passed around in the application. It comes in handy in frame differences, as in the example under samples/imgproc/framedifference.qml
Mat input
property
Input matrix to store. Whenever a new input is given, the previous one becomes available as output.
CamCapture
type
Inherits | MatDisplay |
Property | string Device |
Property | size resolution |
Property | real fps |
Property | bool paused |
Method | CamCapture staticLoad(string device,size resolution) |
Captures frames from a connected camera. This is a static item.
An example of how to use the cam capture can be found in samples/core/camcapture.qml.
string Device
property
This property holds the url to the camera device to be accessed.
size resolution
property
Stores the resolution for this cam capture.
real fps
property
By default, this is initialized with the camera's given fps. You can change this value if you want faster/slower capture playback, however, setting it faster than the actual camera permits will limit to the camera's maximum rate. This value is not absolute, in fact it depends on a lot of factors like processing time done by Livekeys and speed by which frames are delivered.
This is an overloaded method for CamCapture staticLoad
CamCapture staticLoad(string device,size resolution)
method
Loads the CamCaptures state, where device
can be either a link or a device number. The device number should be given
in string form. Usually a default webcam can be accesed by '0'. Resolution
is optional and stores the
resolution at which to open the capture.
bool paused
property
This property can be set to true or false, depending if you want to freeze or continue capturing frames from the camera.
VideoCapture
type
Inherits | Item |
Property | Mat output |
Property | bool linearFilter |
Property | float fps |
Property | bool loop |
Property | int CurrentFrame |
Property | string file |
Property | bool paused |
Method | seek(int frame) |
Method | staticOpen(string file) |
Method | staticLoad(string file) |
Captures frames from video files.This is a static item.
The VideoCapture constantly grabes frames from a video file. The frames are captured at a speed equal to the video's fps, but that is not necessarily to be considered as an absolute value. The speed can be altered manually by configuring the fps parameter. A progress bar and a play/pause button can be attached by using the VideoControls type.
The first example in core/videocapture_simple.qml shows a simple video frame grabber, while the second one in core/videocapture_controls.qml shows the grabber with the VideoControls attached.
samples/core/videocapture_simple.qml
samples/core/videocapture_controls.qml
Mat output
property
Output frame.
bool linearFilter
property
Perform linear filtering when scaling the matrix to be displayed. The default value is true
.
float fps
property
By default, this is initialized with the video files fps. You can change this value if you want faster/slower capture playback.
bool loop
property
If enabled, the video will start over once it's reach the end. By default, this value is false
.
int CurrentFrame
property
This property holds the current frame number. If you set this manually, you perform a seek to the specified frame number in the video.
seek(int frame)
method
Perform a seek to the specified frame number.
string file
property
This property holds the url to the file thats opened.
staticOpen(string file)
method
This is an overloaded method for VideoCapture staticLoad
staticLoad(string file)
method
Loads the VideoCapture state. file
is a link to the file to be opened. This also acts a a state identifier.
bool paused
property
Pause or play the video.
AlphaMerge
type
Inherits | MatFilter |
Property | Mat mask |
Merges an alpha channel to a matrix.
Alpha merge is used to merge an alpha channel to a 1 or 3 channel matrix. The alpha channel is a single channel image or mask that is loaded within the mask property of this class.
In the sample at samples/imgproc/alphamerge.qml a loaded image is merged with a drawn circle.
See samples/imgproc/alphamerge.qml
Mat mask
property
Mask to merge the input with.
AbsDiff
type
Inherits | MatFilter |
Property | Mat input2 |
Performs an absolute difference between two matrixes.
The example in samples/imgproc/framedifference.qml shows differentiating two consecutive frames in a video to calculate the motion. It uses a MatBuffer to store the previous frame:
imgproc/framedifference.qml
Mat input2
property
Second input for the subtraction.
ImageFile
type
Inherits | MatDisplay |
Property | string file |
Property | enumaration isColor |
Property | monitor |
Read an image from the hard drive into a Mat structure.
string file
property
The path to the file to load.
enumaration isColor
property
Color type of the image
Can be one of the following:
ImRead.CV_LOAD_IMAGE_UNCHANGED
ImRead.CV_LOAD_IMAGE_GRAYSCALE
ImRead.CV_LOAD_IMAGE_COLOR
ImRead.CV_LOAD_IMAGE_ANYDEPTH
ImRead.CV_LOAD_IMAGE_ANYCOLOR
monitor
property
Monitors the file for changes and reloads the image if the file has changed.
OverlapMat
type
Inherits | MatDisplay |
Property | input2 |
Property | mask |
Overlaps 2 matrixes
input2
property
Mat to overlap with.
mask
property
Mask used when overlaping.
ItemCapture
type
Inherits | MatDisplay |
Property | Item captureSource |
Captures the screen into a Mat object.
Available through the output
property from MatDisplay
.
Item captureSource
property
Item to capture screen from.
VideoControls
type
Inherits | Rectangle |
Property | VideoCapture videoCapture |
Signal | playPauseTriggered(bool paused) |
Signal | seekTriggered(int currentFrame) |
Video controls provides a play/pause button and a seekbar for VideoCapture
VideoCapture videoCapture
property
The actual videoCapture object
playPauseTriggered(bool paused)
signal
Triggered when play/pause state changed
seekTriggered(int currentFrame)
signal
Triggered when a seek occurred
VideoWriter
type
Inherits | Item |
Property | Mat input |
Property | int framesWritten |
Method | staticLoad(Object parameters) |
Writes video to a file. This is a static item.
Mat input
property
Input matrix to write. Whenever the input is set, the matrix will be written to a file.
int framesWritten
property
Number of frames written. This is a read only property.
staticLoad(Object parameters)
method
Loads the static object, where parameters is an object with the following keys:
filename
: name of the file to write intofourcc
: a string based sequence of characters that describes the codec to be usedfps
: fps of the videoframeWidth
: video frame widthframeHeight
: video frame heightisColor
: boolean flag set to true if the encoder should work with color or greyscale frames. Default is true.
DrawHistogram
type
Inherits | Item |
Enum | RenderType |
Property | list colors |
Property | list values |
Property | real maxValue |
Property | DrawHistogram.RenderType render |
Method | setValuesFromIntList(list values) |
Draws a histogram given from a set of points
Example:
DrawHistogram{
width : 200
height : 200
maxValue : 200
colors : ['#aa007700', '#aa000088']
render : DrawHistogram.ConnectedLines
values : [
[10, 44, 30, 50, 200, 10, 300, 50, 70],
[20, 30, 40, 50, 100, 30, 200, 50, 30]
]
}
RenderType
enum
Type of histogram to render
ConnectedLines
: Points will be connected by a set of linesRectangles
: Rectangle or bar based histogramBinary
: Binary histogramBinaryConverted
: Int values are expected, which will be converted to binary
list colors
property
List of colors associated with the indexes of each histogram graph.
list values
property
List of graphs, each one consisting of a list of values for that graph.
real maxValue
property
Max value shown in the histogram
DrawHistogram.RenderType render
property
Render type of this histogram
setValuesFromIntList(list values)
method
Assigns the values from a list of integers.
{qmlMethod:setValuesFromIntListAt(list values, int index))
Assigns values from the given list only at the specified index.
ColorHistogram
type
Inherits | Item |
Enum | Selection |
Property | Mat input |
Property | Mat output |
Property | bool fill |
Property | int channel |
Calculates histogram for a given matrix
Selection
enum
Channel selection to calculate the histogram for the image.
Total
: calculates the lightness of the imageAllChannels
: Calculates all the channelsBlueChannel
: Calculates the blue channelGreenChannel
: Calculates the green channelRedChannel
: Calculates the red channel
Mat input
property
Input matrix to calculate the histogram for.
Mat output
property
Output matrix containing the drawn histogram.
bool fill
property
Flag that sets wether to fill the resulting graph.
int channel
property
Channel to calculate the histogram for. Can be ColorHistogram.AllChannels
for all the
channels, or ColorHistogram.TotalChannels
to calculate the lightness.