Sunday, February 11, 2018

Vision Video

Getting started with video:

The following example will load up a video from disk . It uses the VideoCapture object.
  • Its argument can be either the device index or the name of a video file. Device usually is the index is just the number to specify which camera to use.  This line below sets the video source to use an existing file.

import numpy as np
import cv2 as cv
cap = cv.VideoCapture('output.mp4')
       ret, frame =
       gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
       if cv.waitKey(1) & 0xFF == ord('q'):


[link]  - tweak for VideoCapture

VideoWriter([filename, fourcc, fps, frameSize, isColor)
  • filename – Name of the output video file.
  • fourcc – 4-character code of codec used to compress the frames. 
  • fps – Framerate of the created video stream.
  • frameSize – Size of the video frames.
  • isColor – If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).

The read() function

  • reads one frame from the video source, which in this example is the webcam. 

This returns two things:
  • The actual video frame read (one frame on each loop) 
  • A return code (True/False). If frame is read correctly.  It tells us if we have run out of frames, which will happen if we are reading from a file. This doesn’t matter when reading from the webcam, since we can record forever, so we will ignore it.
Reading from web camera:

     # Capture frame-by-frame  
     ret, frame =  
    # frame come here  
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)  
    # Display the resulting frame  
    if cv.waitKey(1) & 0xFF == ord('q'):      

# When everything done, release the capture


Saving images from video camera input to a file:


import cv2
import numpy as np
#This line sets the video source to the default webcam, which OpenCV
cap = cv2.VideoCapture(0)
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH);
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT);
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output.mp4',fourcc, 15.0, (int(w),int(h)))

while True:
        ret,frame =
        #---------for gray video--------
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        #Display the resulting frame
        k = cv2.waitKey(0) & 0xFF
        if k == ord('q'):    # wait for 'q' key to exit break


Saturday, February 10, 2018

Vision Overview

In my earlier Python post I mentioned how easy is to install Open CV

OpenCV is the most popular library for computer vision. Originally written in C/C++, it now provides bindings for Python. OpenCV uses machine learning algorithms to search for faces within a picture. For something as complicated as a face, there isn’t one simple test that will tell you if it found a face or not. Instead, there are thousands of small patterns/features that must be matched. The algorithms break the task of identifying the face into thousands of smaller, bite-sized tasks, each of which is easy to solve
Here is what you can do with OpenCV

Well before we start mentioning the provided examples on web site, it is good to have the API search tool - i.e. reading and writing images API

Here as part of the gui features we will read an image from disk. Likewise, we can write a copy of the image to the disk.

Here are some of the methods we will use:

  • file name
  • flag on way image should be read
  • named window name
  • image
  • file name on disk
  • image

import cv2
import numpy as np

#practice numpy


 img = cv2.imread('img.JPG',cv2.IMREAD_GRAYSCALE)

# ----------showing with opencv.........

cv2.imshow('my image',img)
k = cv2.waitKey(0) & 0xFF

if k == 27: # wait for ESC key to exit
elif k == ord('s'): # wait for 's' key to save and exit
       cv2.imwrite('img2.JPG',img) # writing the image


  •  mouse as paint brush

    Wednesday, February 7, 2018

    python everywhere

    Python seems like the hot thing. I have been learning and experimenting.

    I use The following package manager for macOS:

     /usr/bin/ruby -e "$(curl -fsSL" 

    use example: - brew install python


    Install anaconda:


    condo update anaconda

    to install opencv:

    conda install --channel opencv3

    confirm the install from python command line
            import cv2

    spyder is an IDE for perl - for macOs from the cmd line enter to start it:

    console : print "hello"
    editor: run by select f9
    inspector : debugging

    see spyder perl tutorial

    active state
    python tutorial 
    python class python python

    Saturday, April 25, 2015

    Mac Hardware

    mac models

    OS X Yosemite version 10.10 Oct. 2014
    Mavericks version 10.9 Oct. 2013

    mac specs by machine model machine

    apple authorized reseller
    Ten Plus

    The Air wins this round because it’s thinner and lighter

    The Pro’s Retina display blows the Air’s 1440 x 900-pixel panel out of the water an HDMI port and an SDXC card slot. This means that the Pro can support up to two monitors at 2560 x 1600, as well as an additional monitor at 1080p. The Air can only support one external monitor

    Processor and Memory:
    Air comes with a 1.4-GHz Core i5-4260U processor, 4GB of RAM, 128GB of PCI Express storage, and Intel HD 5000 graphics. The 13-inch MacBook Pro, by comparison, features a 2.6-GHz Intel Core i5-4278U processor, 8GB of RAM

    The 13-inch Air lasted 12 hours and 50 minutes on the LAPTOP Battery Test (Web surfing via Wi-Fi).

    The Pro lasted 10 hours and 44 minutes, least expensive version of the 13-inch

    Air costs $999 and comes with a 1.4-GHz Intel Core i5 processor, Intel HD Graphics 5000, 4GB of RAM and 128GB of flash storage.

    The Pro with Retina display starts at $1,299 and includes a 2.6-GHz Intel Core i5 processor, 8GB of RAM, 128GB of flash storage and Intel Iris graphics. The more expensive version of the Air costs $1,199 and has the same processor and RAM as the starting version, but comes with 256GB of storage. - 2 air models - You're going to want to choose a Retina MacBook Pro if you're big on gaming - Get the MacBook Pro if you're a heavy user with processor-intensive tasks, but if you're like most people, and your computing tasks consist mainly of typing and web browsing, get the MacBook instead

    Monday, December 15, 2014


    firebase joins google - g+ page  why

    three way binding:

    We can synchronize our data back to Firebase by using the following methods provided by the $firebase object.

    • $add(value)
    • $remove([key])
    • $save([key])
    • $save()
    • $child(key)
    • $set(value)

    create a free account

    Once you are logged in, you can view your url  on

    plunkr demo #1

    Friday, December 5, 2014

    client side reorder list

    I am looking into jquery ui drag and drop grid row

    Enable a group of DOM elements to be sortable. Click on and drag an element to a new spot within the list, and the other items will adjust to fit. By default, sortable items share draggable properties

    items: Specifies which items inside the element should be sortable
    handle:Restricts sort start click to the specified element.

    stop( event, ui )Type: sortstop This event is triggered when sorting has stopped

    example : 

    Sunday, November 23, 2014

    Coursera Content provider Exercise - week 8

    This lab will build off of the week 7 Location lab. This application will have the same UI elements and behaviors as the week 7 Lab.

    This application, however, manages a user's Place Badges using a ContentProvider.

    Because ContentProviders persist data across application sessions, when the application initially starts up, it should get all existing Place Badges from the ContentProvider and display them on the screen.

    PlaceViewAdapter extends CursorAdapter - see
    - Adapter that exposes data from a Cursor to a ListView widget.
    - swapCursor() : Swap in a new Cursor, returning the old Cursor.

    This is the most important reason why you have to use swapCursor, it doesn’t close the Cursor when you swap it with another Cursor

    - content: scheme indicating data that is managed by content provider
    - authority: id for content provider
    -path: 0 or more segments indicating type of data accessed
    -id : optional is specific record within dataset

    Provider: ContentProviderCustom

    course.examples.ContentProviders.StringContentProvider.StringsContentProvider class

    public synchronized Uri insert(Uri uri, ContentValues value) {

    User: ContentProviderCustomUser

    DataContract class:
    public static final String _ID = "_id";public static final String DATA = "data";public static final String DATA_TABLE = "data_table";
    private static final Uri BASE_URI = Uri.parse("content://course.examples.ContentProviders.StringContentProvider/");
    // The URI for this table.
    public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_URI,

    CustomContactProviderDemo class:
    ContentValues values = new ContentValues();
    // Insert first record
    values.put(DataContract.DATA, "Record1");
    Uri firstRecordUri = contentResolver.insert(DataContract.CONTENT_URI, values);