PDL::OpenCV::Highgui - PDL bindings for OpenCV Highgui
use PDL::OpenCV::Highgui;
Creates a window.
namedWindow($winname); # with defaults namedWindow($winname,$flags);
The function namedWindow creates a window that can be used as a placeholder for images and trackbars. Created windows are referred to by their names. If a window with the same name already exists, the function does nothing. You can call cv::destroyWindow or cv::destroyAllWindows to close the window and de-allocate any associated memory usage. For a simple program, you do not really have to call these functions because all the resources and windows of the application are closed automatically by the operating system upon exit. @note Qt backend supports additional flags: - **WINDOW_NORMAL or WINDOW_AUTOSIZE:** WINDOW_NORMAL enables you to resize the window, whereas WINDOW_AUTOSIZE adjusts automatically the window size to fit the displayed image (see imshow ), and you cannot change the window size manually. - **WINDOW_FREERATIO or WINDOW_KEEPRATIO:** WINDOW_FREERATIO adjusts the image with no respect to its ratio, whereas WINDOW_KEEPRATIO keeps the image ratio. - **WINDOW_GUI_NORMAL or WINDOW_GUI_EXPANDED:** WINDOW_GUI_NORMAL is the old way to draw the window without statusbar and toolbar, whereas WINDOW_GUI_EXPANDED is a new enhanced GUI. By default, flags == WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | WINDOW_GUI_EXPANDED
Parameters:
Name of the window in the window caption that may be used as a window identifier.
Flags of the window. The supported flags are: (cv::WindowFlags)
Destroys the specified window.
destroyWindow($winname);
The function destroyWindow destroys the window with the given name.
Name of the window to be destroyed.
Destroys all of the HighGUI windows.
destroyAllWindows;
The function destroyAllWindows destroys all of the opened HighGUI windows.
$res = startWindowThread;
Similar to #waitKey, but returns full key code.
$res = waitKeyEx; # with defaults $res = waitKeyEx($delay);
@note Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc
Waits for a pressed key.
$res = waitKey; # with defaults $res = waitKey($delay);
The function waitKey waits for a key event infinitely (when \texttt{delay}\leq 0) or for delay milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is running on your computer at that time. It returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed. To check for a key press but not wait for it, use #pollKey. @note The functions #waitKey and #pollKey are the only methods in HighGUI that can fetch and handle GUI events, so one of them needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing. @note The function only works if there is at least one HighGUI window created and the window is active. If there are several HighGUI windows, any of them can be active.
\texttt{delay}\leq 0
Delay in milliseconds. 0 is the special value that means "forever".
Polls for a pressed key.
$res = pollKey;
The function pollKey polls for a key event without waiting. It returns the code of the pressed key or -1 if no key was pressed since the last invocation. To wait until a key was pressed, use #waitKey. @note The functions #waitKey and #pollKey are the only methods in HighGUI that can fetch and handle GUI events, so one of them needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing. @note The function only works if there is at least one HighGUI window created and the window is active. If there are several HighGUI windows, any of them can be active.
Signature: ([phys] mat(l2,c2,r2); StringWrapper* winname)
Displays an image in the specified window.
imshow($winname,$mat);
The function imshow displays an image in the specified window. If the window was created with the cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution. Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth: - If the image is 8-bit unsigned, it is displayed as is. - If the image is 16-bit unsigned, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255]. - If the image is 32-bit or 64-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255]. - 32-bit integer images are not processed anymore due to ambiguouty of required transform. Convert to 8-bit unsigned matrix using a custom preprocessing specific to image's context. If window was created with OpenGL support, cv::imshow also support ogl::Buffer , ogl::Texture2D and cuda::GpuMat as input. If the window was not created before this function, it is assumed creating a window with cv::WINDOW_AUTOSIZE. If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow. @note This function should be followed by a call to cv::waitKey or cv::pollKey to perform GUI housekeeping tasks that are necessary to actually show the given image and make the window respond to mouse and keyboard events. Otherwise, it won't display the image and the window might lock up. For example, **waitKey(0)** will display the window infinitely until any keypress (it is suitable for image display). **waitKey(25)** will display a frame and wait approximately 25 ms for a key press (suitable for displaying a video frame-by-frame). To remove the window, use cv::destroyWindow. @note [__Windows Backend Only__] Pressing Ctrl+C will copy the image to the clipboard. [__Windows Backend Only__] Pressing Ctrl+S will show a dialog to save the image.
Name of the window.
Image to be shown.
imshow ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Resizes the window to the specified size
resizeWindow($winname,$width,$height);
@note - The specified window size is for the image area. Toolbars are not counted. - Only windows created without cv::WINDOW_AUTOSIZE flag can be resized.
Window name.
The new window width.
The new window height.
Signature: (indx [phys] size(n2=2); StringWrapper* winname)
resizeWindow2($winname,$size);
@overload
The new window size.
resizeWindow2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Moves the window to the specified position
moveWindow($winname,$x,$y);
The new x-coordinate of the window.
The new y-coordinate of the window.
Changes parameters of a window dynamically.
setWindowProperty($winname,$prop_id,$prop_value);
The function setWindowProperty enables changing properties of a window.
Window property to edit. The supported operation flags are: (cv::WindowPropertyFlags)
New value of the window property. The supported flags are: (cv::WindowFlags)
Updates window title
setWindowTitle($winname,$title);
New title.
Provides parameters of a window.
$res = getWindowProperty($winname,$prop_id);
The function getWindowProperty returns properties of a window.
Window property to retrieve. The following operation flags are available: (cv::WindowPropertyFlags)
See also: setWindowProperty
Signature: (indx [o,phys] res(n2=4); StringWrapper* winname)
Provides rectangle of image in the window.
$res = getWindowImageRect($winname);
The function getWindowImageRect returns the client screen coordinates, width and height of the image rendering area.
See also: resizeWindow moveWindow
getWindowImageRect ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: ([phys] img(l2,c2,r2); byte [phys] showCrosshair(); byte [phys] fromCenter(); indx [o,phys] res(n5=4); StringWrapper* windowName)
Allows users to select a ROI on the given image.
$res = selectROI($windowName,$img); # with defaults $res = selectROI($windowName,$img,$showCrosshair,$fromCenter);
The function creates a window and allows users to select a ROI using the mouse. Controls: use `space` or `enter` to finish selection, use key `c` to cancel selection (function will return the zero cv::Rect). @note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). After finish of work an empty callback will be set for the used window.
name of the window where selection process will be shown.
image to select a ROI.
if true crosshair of selection rectangle will be shown.
if true center of selection will match initial mouse position. In opposite case a corner of selection rectangle will correspont to the initial mouse position.
Returns: selected ROI or empty rect if selection canceled.
selectROI ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: ([phys] img(l1,c1,r1); byte [phys] showCrosshair(); byte [phys] fromCenter(); indx [o,phys] res(n4=4))
$res = selectROI2($img); # with defaults $res = selectROI2($img,$showCrosshair,$fromCenter);
selectROI2 ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Signature: ([phys] img(l2,c2,r2); indx [o,phys] boundingBoxes(n3=4,n3d0); byte [phys] showCrosshair(); byte [phys] fromCenter(); StringWrapper* windowName)
Allows users to select multiple ROIs on the given image. NO BROADCASTING.
$boundingBoxes = selectROIs($windowName,$img); # with defaults $boundingBoxes = selectROIs($windowName,$img,$showCrosshair,$fromCenter);
The function creates a window and allows users to select multiple ROIs using the mouse. Controls: use `space` or `enter` to finish current selection and start a new one, use `esc` to terminate multiple ROI selection process. @note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). After finish of work an empty callback will be set for the used window.
selected ROIs.
selectROIs ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Returns the trackbar position.
$res = getTrackbarPos($trackbarname,$winname);
The function returns the current position of the specified trackbar. @note [__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel.
Name of the trackbar.
Name of the window that is the parent of the trackbar.
Sets the trackbar position.
setTrackbarPos($trackbarname,$winname,$pos);
The function sets the position of the specified trackbar in the specified window. @note [__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel.
Name of the window that is the parent of trackbar.
New position.
Sets the trackbar maximum position.
setTrackbarMax($trackbarname,$winname,$maxval);
The function sets the maximum position of the specified trackbar in the specified window. @note [__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel.
New maximum position.
Sets the trackbar minimum position.
setTrackbarMin($trackbarname,$winname,$minval);
The function sets the minimum position of the specified trackbar in the specified window. @note [__Qt Backend Only__] winname can be empty if the trackbar is attached to the control panel.
New minimum position.
Signature: ([phys] img(l1,c1,r1); indx [phys] org(n3=2); int [phys] pointSize(); double [phys] color(n6=4); int [phys] weight(); int [phys] style(); int [phys] spacing(); StringWrapper* text; StringWrapper* nameFont)
Draws a text on the image.
addText($img,$text,$org,$nameFont); # with defaults addText($img,$text,$org,$nameFont,$pointSize,$color,$weight,$style,$spacing);
8-bit 3-channel image where the text should be drawn.
Text to write on an image.
Point(x,y) where the text should start on an image.
Name of the font. The name should match the name of a system font (such as *Times*). If the font is not found, a default one is used.
Size of the font. If not specified, equal zero or negative, the point size of the font is set to a system-dependent default value. Generally, this is 12 points.
Color of the font in BGRA where A = 255 is fully transparent.
Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control.
Font style. Available operation flags are : cv::QtFontStyles
Spacing between characters. It can be negative or positive.
addText ignores the bad-value flag of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
Displays a text on a window image as an overlay for a specified duration.
displayOverlay($winname,$text); # with defaults displayOverlay($winname,$text,$delayms);
The function displayOverlay displays useful information/tips on top of the window for a certain amount of time *delayms*. The function does not modify the image, displayed in the window, that is, after the specified delay the original content of the window is restored.
Overlay text to write on a window image.
The period (in milliseconds), during which the overlay text is displayed. If this function is called before the previous overlay text timed out, the timer is restarted and the text is updated. If this value is zero, the text never disappears.
Displays a text on the window statusbar during the specified period of time.
displayStatusBar($winname,$text); # with defaults displayStatusBar($winname,$text,$delayms);
The function displayStatusBar displays useful information/tips on top of the window for a certain amount of time *delayms* . This information is displayed on the window statusbar (the window must be created with the CV_GUI_EXPANDED flags).
Text to write on the window statusbar.
Duration (in milliseconds) to display the text. If this function is called before the previous text timed out, the timer is restarted and the text is updated. If this value is zero, the text never disappears.
To install PDL::OpenCV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDL::OpenCV
CPAN shell
perl -MCPAN -e shell install PDL::OpenCV
For more information on module installation, please visit the detailed CPAN module installation guide.