Update to 2.0.0 tree from current Fremantle build
[opencv] / interfaces / matlab / toolbox / opencv / cvdemos / contdemo.m
diff --git a/interfaces/matlab/toolbox/opencv/cvdemos/contdemo.m b/interfaces/matlab/toolbox/opencv/cvdemos/contdemo.m
deleted file mode 100644 (file)
index d3a6826..0000000
+++ /dev/null
@@ -1,494 +0,0 @@
-function contdemo(action,varargin);\r
-%   OpenCV contour functions demo\r
-\r
-global demoName;\r
-demoName = 'OpenCV Contour Demo';\r
-if nargin<1,\r
-   action='InitializeDEMO';\r
-end;\r
-\r
-feval(action,varargin{:});\r
-return;\r
-\r
-\r
-%%%\r
-%%%  Sub-function - InitializeDEMO\r
-%%%\r
-\r
-function InitializeDEMO()\r
-\r
-global demoName;\r
-\r
-% If demo is already running, bring it to the foreground.\r
-h = findobj(allchild(0), 'tag', demoName);\r
-if ~isempty(h)\r
-   figure(h(1))\r
-   return\r
-end\r
-\r
-screenD = get(0, 'ScreenDepth');\r
-if screenD>8\r
-   grayres=256;\r
-else\r
-   grayres=128;\r
-end\r
\r
-DemoFig=figure( ...\r
-   'Name',demoName, ...\r
-   'NumberTitle','off', 'HandleVisibility', 'on', ...\r
-   'tag', demoName, ...\r
-   'Visible','off', 'Resize', 'off',...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'IntegerHandle', 'off', ...\r
-   'Doublebuffer', 'on', ...\r
-   'Colormap', gray(grayres));\r
-\r
-%====================================\r
-% Information for all buttons (and menus)\r
-btnWid=0.175;\r
-btnHt=0.06;\r
-\r
-%====================================\r
-% The CONSOLE frame\r
-frmBorder=0.02;\r
-frmBottom = 0.15;\r
-\r
-frmLeft = 0.5-btnWid-1.5*frmBorder;\r
-frmWidth = 2*btnWid+3*frmBorder;\r
-frmHeight = btnHt+2*frmBorder;\r
-frmPos=[frmLeft frmBottom frmWidth frmHeight];\r
-h=uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','frame', ...\r
-   'Units','normalized', ...\r
-   'Position',frmPos, ...\r
-   'BackgroundColor',[0.45 0.45 0.45]);\r
-\r
-%====================================\r
-% The Apply button\r
-labelStr='Apply';\r
-callbackStr='contdemo(''Apply'')';\r
-yPos=frmBottom+frmBorder;\r
-applyHndl=uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','pushbutton', ...\r
-   'Units','normalized', ...\r
-   'Position',[frmLeft+frmBorder yPos btnWid btnHt], ...\r
-   'String',labelStr, ...\r
-   'Enable', 'off', ...\r
-   'Callback',callbackStr);\r
-\r
-\r
-%====================================\r
-% The CLOSE button\r
-labelStr='Close';\r
-callbackStr='close(gcf)';\r
-\r
-closeHndl=uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','pushbutton', ...\r
-   'Units','normalized', ...\r
-   'Position',[frmLeft+btnWid+2*frmBorder yPos btnWid btnHt], ...\r
-   'Enable', 'off', ...\r
-   'String',labelStr, ...\r
-   'Callback',callbackStr);\r
-\r
-c = get(DemoFig,'Color');\r
-if [.298936021 .58704307445 .114020904255]*c'<.5,\r
-   fgColor = [1 1 1];\r
-else\r
-   fgColor = [0 0 0];\r
-end\r
-\r
-%==================================\r
-% Set up the image axes\r
-figpos = get(DemoFig, 'position');\r
-row = figpos(4); col = figpos(3);  % dimensions of figure window\r
-\r
-vertSpac = (row-256)/3;\r
-horSpac = (col-3*128)/4;\r
-hSrcAx = axes('Parent', DemoFig, ...\r
-   'units', 'pixels', ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'ydir', 'reverse', ...\r
-   'XLim', [.5 128.5], ...\r
-   'YLim', [.5 128.5],...\r
-   'CLim', [0 255], ...\r
-   'XTick',[],'YTick',[], ...\r
-   'Position', [horSpac row-vertSpac-128 128 128]);\r
-title('Source Image');\r
-\r
-hBinAx = axes('Parent', DemoFig, ...\r
-   'units', 'pixels', ...\r
-   'BusyAction','Queue', 'Interruptible','off',...\r
-   'ydir', 'reverse', ...\r
-   'XLim', [.5 128.5], ...\r
-   'YLim', [.5 128.5],...\r
-   'CLim', [0 255], ...\r
-   'XTick',[],'YTick',[], ...\r
-   'Position', [2*horSpac + 128 row - vertSpac-128 128 128]);\r
-title('Threshold Image');\r
-\r
-hContAx = axes('Parent', DemoFig, ...\r
-   'units', 'pixels', ...\r
-   'BusyAction','Queue', 'Interruptible','off',...\r
-   'ydir', 'reverse', ...\r
-   'XLim', [.5 128.5], ...\r
-   'YLim', [.5 128.5],...\r
-   'CLim', [0 255], ...\r
-   'XTick',[],'YTick',[], ...\r
-   'Position', [3*horSpac + 256 row - vertSpac-128 128 128]);\r
-title('Contour Image');\r
-\r
-%==================================\r
-% Set up the images\r
-blank = repmat(uint8(0),128,128);\r
-hSrcImage = image('Parent', hSrcAx,...\r
-   'CData', blank, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'CDataMapping', 'scaled', ...\r
-   'Xdata', [1 128],...\r
-   'Ydata', [1 128],...\r
-   'EraseMode', 'none');\r
-\r
-hBinImage = image('Parent', hBinAx,...\r
-   'CData', blank, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'CDataMapping', 'scaled', ...\r
-   'Xdata', [1 128],...\r
-   'Ydata', [1 128],...\r
-   'EraseMode', 'none');\r
-\r
-hContImage = image('Parent', hContAx,...\r
-   'CData', blank, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'CDataMapping', 'scaled', ...\r
-   'Xdata', [1 128],...\r
-   'Ydata', [1 128],...\r
-   'EraseMode', 'none');\r
-\r
-% Status bar\r
-% rangePos = [64 3 280 15];\r
-rangePos = [0 .01 1 .05];\r
-hStatus = uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','normalized', ...\r
-   'Position',rangePos, ...\r
-   'Horiz','center', ...\r
-   'Background',c, ...\r
-   'Foreground',[.8 0 0], ...\r
-   'Tag', 'Status', ...\r
-   'String','Status bar');\r
-\r
-%====================================\r
-% The Threshold Popup\r
-ctrHt = 19; % controls' height\r
-binImgPos = get(hBinAx, 'Position');\r
-pos = [binImgPos(1) binImgPos(2) - 3*ctrHt binImgPos(3) ctrHt];\r
-hThreshPop=uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','popupmenu', ...\r
-   'BackgroundColor',[.8 .8 .8], ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'String','binary|binary_inv|trunc|tozero|tozero_inv', ...\r
-   'Tag','ThreshPop', ...\r
-   'Callback','contdemo(''ControlsUpdate'')');\r
-%====================================\r
-% The Threshold Label\r
-pos = [binImgPos(1) binImgPos(2) - 2*ctrHt binImgPos(3) ctrHt];\r
-h = uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Horiz','center', ...\r
-   'Background',c, ...\r
-   'Foreground','black', ...\r
-   'String','Threshold Type:');\r
-\r
-%===================================\r
-% Set up scroll bar\r
-thresh = 128;\r
-\r
-pos = [binImgPos(1) binImgPos(2) - 5*ctrHt binImgPos(3) ctrHt];\r
-callbackStr = 'contdemo(''ControlsUpdate'')';\r
-hSlider = uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','slider', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Value',thresh, ...\r
-   'min',0, ...\r
-   'max',255, ...\r
-   'Interruptible','off', ...\r
-   'Callback',callbackStr);\r
-\r
-% Left and right range indicators\r
-pos = [binImgPos(1) binImgPos(2) - 6*ctrHt binImgPos(3)/2 ctrHt];\r
-uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Horiz','left', ...\r
-   'Background',c, ...\r
-   'Foreground',fgColor, ...\r
-   'String','0');\r
-\r
-pos = [binImgPos(1)+binImgPos(3)/2 binImgPos(2) - 6*ctrHt binImgPos(3)/2 ctrHt];\r
-uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Horiz','right', ...\r
-   'Background',c, ...\r
-   'Foreground',fgColor, ...\r
-   'String','255');\r
-\r
-pos = [binImgPos(1) binImgPos(2) - 4*ctrHt binImgPos(3) ctrHt];\r
-hThresh = uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Horiz','center', ...\r
-   'Background',c, ...\r
-   'Foreground',fgColor, ...\r
-   'String',['Threshold: ' int2str(thresh)]);\r
-\r
-%====================================\r
-% The Approx Popup\r
-contImgPos = get(hContAx, 'Position');\r
-pos = [contImgPos(1) contImgPos(2) - 3*ctrHt contImgPos(3) ctrHt];\r
-hAppPop=uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','popupmenu', ...\r
-   'BackgroundColor',[.8 .8 .8], ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'String','none|simple|tc89_l1|tc89_kcos|dp', ...\r
-   'Tag','ThreshPop', ...\r
-   'Callback','contdemo(''ControlsUpdate'')');\r
-%====================================\r
-% The Approx Label\r
-pos = [contImgPos(1) contImgPos(2) - 2*ctrHt contImgPos(3) ctrHt];\r
-h = uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Horiz','center', ...\r
-   'Background',c, ...\r
-   'Foreground','black', ...\r
-   'String','Approx Type:');\r
-\r
-%====================================\r
-% The Approx Edit\r
-pos = [contImgPos(1) contImgPos(2) - 5*ctrHt contImgPos(3) ctrHt];\r
-hAppEdit=uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','edit', ...\r
-   'Background','white', ...\r
-   'Foreground','black', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'String','1.0', ...\r
-   'Horiz', 'right',...\r
-   'Tag','AppEdit', ...\r
-   'Enable', 'off', ...\r
-   'UserData', [1.0], ...\r
-   'Callback','contdemo(''ControlsUpdate'')');\r
-%====================================\r
-% The Approx Edit Label\r
-pos = [contImgPos(1) contImgPos(2) - 4*ctrHt contImgPos(3) ctrHt];\r
-h = uicontrol( ...\r
-   'Parent', DemoFig, ...\r
-   'BusyAction','Queue','Interruptible','off',...\r
-   'Style','text', ...\r
-   'Units','pixels', ...\r
-   'Position',pos, ...\r
-   'Horiz','center', ...\r
-   'Background',c, ...\r
-   'Foreground','black', ...\r
-   'String','Approx Param:');\r
-\r
-%set(DemoFig,'defaultaxesposition',[0.10 0.1 0.60 0.85])\r
-setstatus(DemoFig, 'Initializing Demo...');\r
-set(DemoFig, 'Pointer', 'watch');\r
-drawnow\r
-set(DemoFig, 'Visible','on');\r
-\r
-% Put handles to graphics objects and controls in the figure's userdata\r
-handles.SrcImage = hSrcImage;\r
-handles.BinImage = hBinImage;\r
-handles.ContImage = hContImage;\r
-handles.Slider = hSlider; \r
-handles.Thresh = hThresh;\r
-handles.SrcAx = hSrcAx;\r
-handles.BinAx = hBinAx;\r
-handles.ContAx = hContAx;\r
-handles.ThreshPop = hThreshPop;\r
-handles.AppPop = hAppPop;\r
-handles.AppEdit = hAppEdit;\r
-\r
-set(DemoFig, 'UserData', handles);\r
-\r
-LoadNewImage(DemoFig);\r
-\r
-set(DemoFig, 'HandleVisibility','Callback')\r
-set([closeHndl applyHndl], 'Enable', 'on');\r
-return\r
-\r
-\r
-%%%\r
-%%%  Sub-Function - LoadNewImage\r
-%%%\r
-\r
-function LoadNewImage(DemoFig)\r
-\r
-if nargin<1\r
-   DemoFig = gcbf;\r
-end\r
-\r
-set(DemoFig,'Pointer','watch');\r
-handles = get(DemoFig,'UserData');\r
-hSrcImage=handles.SrcImage;\r
-hSrcAx = handles.SrcAx;\r
-\r
-saturn = [];  % Make sure saturn is parsed as a variable\r
-load cvdemos saturn\r
-\r
-img = saturn;\r
-\r
-set(hSrcImage, 'Cdata', img);\r
-blank = repmat(uint8(0),128,128);\r
-set(handles.BinImage, 'Cdata', blank);\r
-drawnow;\r
-\r
-ControlsUpdate(DemoFig);\r
-Apply(DemoFig);\r
-return;\r
-\r
-\r
-%%%\r
-%%%  Sub-Function - Apply\r
-%%%\r
-\r
-function Apply(DemoFig)\r
-\r
-if nargin<1\r
-   DemoFig = gcbf;\r
-end\r
-\r
-handles = get(DemoFig,'UserData');\r
-hSrcImage=handles.SrcImage;\r
-hBinImage=handles.BinImage;\r
-hSlider=handles.Slider;\r
-hBinAx=handles.BinAx;\r
-hContImage = handles.ContImage;\r
-hThreshPop = handles.ThreshPop;\r
-hAppPop = handles.AppPop;\r
-hAppEdit = handles.AppEdit;\r
-\r
-img = get(hSrcImage, 'CData');\r
-\r
-set(DemoFig,'Pointer','watch');\r
-setstatus(DemoFig, 'Binarizing image...'); drawnow;\r
-\r
-% Binarize and display image\r
-\r
-thresh = floor(get(hSlider, 'Value'));\r
-\r
-% threshType\r
-v = get(hThreshPop,{'value','String'});\r
-threshType = deblank(v{2}(v{1},:));\r
-\r
-binImage = cvThreshold(img, thresh, 255, threshType);\r
-set(hBinImage, 'CData', binImage);\r
-\r
-contImage = repmat(uint8(0), size(img));\r
-contImage = binImage;\r
-\r
-% approx type\r
-v = get(hAppPop,{'Value','String'});\r
-appType = deblank(v{2}(v{1},:));\r
-\r
-% approx value\r
-appVal = get(hAppEdit, 'UserData');\r
-\r
-if strcmp(appType, 'dp') == 0\r
-    Contours = cvFindContours(contImage, 'list', appType);\r
-else\r
-    Cont = cvFindContours(contImage, 'list', 'none');\r
-    Contours = cvApproxPoly(Cont, 1, 'dp', appVal, 1);\r
-end\r
-\r
-contImage = repmat(uint8(0), size(img));\r
-contImage = cvDrawContours(contImage, Contours, 1, 255, 255, 1);\r
-\r
-set(hContImage, 'CData', contImage);\r
-\r
-drawnow;\r
-\r
-setstatus(DemoFig, 'Done');\r
-set(DemoFig,'Pointer','arrow'); drawnow\r
-return\r
-\r
-\r
-%%%\r
-%%%  Sub-function - ControlsUpdate\r
-%%%\r
-\r
-function ControlsUpdate(DemoFig)\r
-\r
-if nargin<1\r
-   DemoFig = gcbf;\r
-end;\r
-\r
-handles = get(DemoFig,'UserData');\r
-\r
-hSlider=handles.Slider;\r
-hThresh = handles.Thresh;\r
-hAppEdit = handles.AppEdit;\r
-hAppPop  = handles.AppPop;\r
-\r
-% threshold value\r
-thresh = floor(get(hSlider, 'Value'));\r
-set(hThresh, 'String', ['Threshold: ' int2str(thresh)]);\r
-\r
-% approx value\r
-oldv = get(hAppEdit, 'UserData');\r
-newv = str2num(get(hAppEdit, 'String'));\r
-if isempty(newv) | newv(1) < 0\r
-    newv = oldv;\r
-end\r
-set(hAppEdit, 'String', num2str(newv(1)));\r
-set(hAppEdit, 'UserData', newv(1));\r
-\r
-% approx type\r
-v = get(hAppPop,{'Value','String'});\r
-appType = deblank(v{2}(v{1},:));\r
-if strcmp(appType, 'dp') == 0\r
-    set(hAppEdit, 'Enable', 'off');\r
-else\r
-    set(hAppEdit, 'Enable', 'on');\r
-end\r
-\r
-setstatus(DemoFig, 'Press ''Apply'' button');\r
-return;\r