// FILE: scilabHelloVision1_0a.sce - Works!
// DATE: 01/16/20 18:10
// AUTH: P.Oh
// REFS: video_capture.dem.sce in Scilab (may need install of image tools)
//       Scilab Computer Vision Module (scicv) is the Scilab interface to the 
//       OpenCV library https://atoms.scilab.org/toolboxes/scicv/0.3
// DESC: Display what USB webcam sees


// (1) initialize the Scilab Computer Vision Module
scicv_Init(); 

// (2) Get ID of the webcam (assumes only 1 webcam connected)
videoCapture = new_VideoCapture(0); 

// (3) Set up a current graphic figure (window) - which will display our video
f = scf(); 

// (4) Make window pretty
// uicontrol allows one to write text in figure with Background color and position 
// Values used sets white background approximately centered below frame 
 
uicontrol(f, "string", "Smile!", "backgroundColor", [1,1,1], "position", [100,40,320,20]);

// (5) Endless loop that grabs frame, displays it, and repeats
while is_handle_valid(f)

    [ret, frame] = VideoCapture_read(videoCapture); // grab and return a frame
  
    if is_handle_valid(f) then
        // ret is TRUE, so display frame
        matplot(frame);
    end

    delete_Mat(frame);

end

