It computes a new rectangle from two input rectangles. The new rectangle is the smallest rectangle that will bound both inputs.
Code: Select all
IncludeFile "includes/cv_functions.pbi"
Global ExitCV.b, lpPrevWndFunc
#CV_WINDOW_NAME = "PureBasic Interface to OpenCV"
#CV_DESCRIPTION = "Computes a new rectangle from two input rectangles. The new rectangle is the smallest rectangle that will bound both inputs."
ImportC "opencv_imgproc247.lib"
cvMaxRect(*maxrect, *rect1, *rect2)
EndImport
Procedure WindowCallback(hWnd, Msg, wParam, lParam)
Select Msg
Case #WM_COMMAND
Select wParam
Case 1
keybd_event_(#VK_ESCAPE, 0, 0, 0)
EndSelect
Case #WM_DESTROY
ExitCV = #True
EndSelect
ProcedureReturn CallWindowProc_(lpPrevWndFunc, hWnd, Msg, wParam, lParam)
EndProcedure
ProcedureC CvMouseCallback(event, x, y, flags, *param.USER_INFO)
Select event
Case #CV_EVENT_RBUTTONDOWN
DisplayPopupMenu(0, *param\uValue)
EndSelect
EndProcedure
Rect1.CvRect
Rect2.CvRect
MaxRect.CvRect
font.CvFont
cvNamedWindow(#CV_WINDOW_NAME, #CV_WINDOW_NORMAL)
window_handle = cvGetWindowHandle(#CV_WINDOW_NAME)
*window_name = cvGetWindowName(window_handle)
lpPrevWndFunc = SetWindowLongPtr_(window_handle, #GWL_WNDPROC, @WindowCallback())
If CreatePopupImageMenu(0, #PB_Menu_ModernLook)
MenuItem(1, "Exit")
EndIf
hwnd = GetParent_(window_handle)
ExtractIconEx_("shell32.dll", 1, #Null, @phiconSmall, 1)
SendMessage_(hwnd, #WM_SETICON, 0, phiconSmall)
wStyle = GetWindowLongPtr_(hwnd, #GWL_STYLE)
SetWindowLongPtr_(hwnd, #GWL_STYLE, wStyle & ~(#WS_MAXIMIZEBOX | #WS_MINIMIZEBOX | #WS_SIZEBOX))
*image.IplImage = cvCreateImage(600, 400, #IPL_DEPTH_8U, 3)
cvResizeWindow(#CV_WINDOW_NAME, *image\width, *image\height)
cvMoveWindow(#CV_WINDOW_NAME, 20, 20)
ToolTip(window_handle, #CV_DESCRIPTION)
rect1\x = 40
rect1\y = 100
rect1\height = 150
rect1\width = 50
cvRectangleR(*image, rect1\x, rect1\y, rect1\width, rect1\height, 50, 50, 255, 0, 1, CV_AA, 0);
rect2\x = 110
rect2\y = 50
rect2\height = 100
rect2\width = 60
cvRectangleR(*image, rect2\x, rect2\y, rect2\width, rect2\height, 50, 255, 50, 0, 1, CV_AA, 0);
cvMaxRect(@maxrect, @rect1, @rect2)
cvRectangleR(*image, maxrect\x-2, maxrect\y-2, maxrect\width+4, maxrect\height+4, 0, 255, 255, 0, 1, CV_AA, 0);
rect1\x = 210
rect1\y = 250
rect1\height = 60
rect1\width = 150
cvRectangleR(*image, rect1\x, rect1\y, rect1\width, rect1\height, 50, 50, 255, 0, 1, CV_AA, 0);
rect2\x = 250
rect2\y = 125
rect2\height = 200
rect2\width = 90
cvRectangleR(*image, rect2\x, rect2\y, rect2\width, rect2\height, 50, 255, 50, 0, 1, CV_AA, 0);
cvMaxRect(@maxrect, @rect1, @rect2)
cvRectangleR(*image, maxrect\x-2, maxrect\y-2, maxrect\width+4, maxrect\height+4, 0, 255, 255, 0, 1, CV_AA, 0);
cvInitFont(@font, #CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, #Null, 1, #CV_AA)
cvPutText(*image, "Rectangle1 - red", 400, 60, @font, 50, 50, 255, 0)
cvPutText(*image, "Rectangle2 - green", 400, 100, @font, 50, 255, 50, 0)
cvPutText(*image, "MaxRectangle - yellow", 400, 140, @font, 50, 255, 255, 0)
*param.USER_INFO = AllocateMemory(SizeOf(USER_INFO))
*param\uValue = window_handle
cvSetMouseCallback(*window_name, @cvMouseCallback(), *param)
Repeat
If *image
cvShowImage(#CV_WINDOW_NAME, *image)
keyPressed = cvWaitKey(0)
EndIf
Until keyPressed = 27 Or ExitCV
FreeMemory(*param)
cvReleaseImage(@*image)
cvDestroyWindow(#CV_WINDOW_NAME)