Sunday, February 11, 2018

Vision Video


Getting started with video:
http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html#display-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')
while(cap.isOpened()):
       ret, frame = cap.read()
       gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
       cv.imshow('frame',gray)
       if cv.waitKey(1) & 0xFF == ord('q'):
             break
cap.release()
cv.destroyAllWindows()

#------------------------------------------------------------

[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:

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

# When everything done, release the capture
cap.release()
cv.destroyAllWindows()

#------------------------------------------------------------


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 = cap.read()
        #---------for gray video--------
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        out.write(frame)

        #Display the resulting frame
        cv2.imshow('myvideo',frame)
        cv2.imshow('myvideo',gray)
        cv2.waitKey(0)      
        k = cv2.waitKey(0) & 0xFF
        if k == ord('q'):    # wait for 'q' key to exit break
                break
cap.release()
out.release()
cv2.destroyAllWindows()


#------------------------------------------------------------

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:

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



#------------------------------------------------------------
import cv2
import numpy as np

#practice numpy
#https://www.w3resource.com/python-exercises/numpy/index.php#EDITOR

# IMREAD_GRAYSCALE = 0
# IMREAD_COLOR = 1
# IMREAD_UNCHANGED = -1

 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
      cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
       cv2.imwrite('img2.JPG',img) # writing the image
       cv2.destroyAllWindows()

#------------------------------------------------------------





  •  mouse as paint brush
  •             https://docs.opencv.org/master/db/d5b/tutorial_py_mouse_handling.html


    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:  https://brew.sh/

     /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

    use example: - brew install python

    anaconda https://www.youtube.com/watch?v=8JiWEZEnJ40

    Install anaconda:

    • https://repo.continuum.io/archive/Anaconda3-4.2.0-Windows-x86_64.exe 
    • https://repo.continuum.io/archive/Anaconda3-4.2.0-MacOSX-x86_64.pkg


    condo update anaconda

    to install opencv:

    conda install --channel https://conda.anaconda.org/menpo opencv3

    confirm the install from python command line
            import cv2
            cv2.__version__

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

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

    see spyder perl tutorial https://www.youtube.com/watch?v=J5GevIHNctM


    http://www.numpy.org/
    • https://www.w3resource.com/python-exercises/numpy/index.php

      https://www.scipy.org


    active state
    python tutorial https://pythonprogramming.net/introduction-to-python-programming/

    https://www.youtube.com/watch?list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M&time_continue=163&v=IX6mc9l6tY4

    https://www.youtube.com/watch?v=5aP9Bl9hcqI

    https://docs.cs50.net/2016/fall/notes/8/week8.html
    https://www.cs.cornell.edu/courses/cs1110/2017fa/lectures/index.php 
    python class http://stanfordpython.com/#lecture
    http://arc-ts.umich.edu/mini-course-introduction-to-python-sept-11-14/ python https://stanford.edu/~schmit/cme193/ python

    https://github.com/wgong/py4kids

    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
    https://www.powermax.com/
    http://www.macconnection.com/
    http://www.macmall.com/
    Ten Plus

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

    Display:
    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

    Battery:
    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

    Cost:
    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.

    http://www.trustedreviews.com/opinions/macbook-pro-vs-macbook-air - 2 air models

    http://www.macrumors.com/guide/which-macbook-to-buy/ - You're going to want to choose a Retina MacBook Pro if you're big on gaming


    http://www.techtimes.com/articles/38970/20150312/macbook-2015-vs-macbook-air-vs-macbook-pro-whats-the-best-macbook-to-buy.htm - 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

    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 https://www.firebase.com/account/#/

    https://www.firebase.com/tutorial/

    https://www.firebase.com/docs/web/quickstart.html

    https://www.firebase.com/docs/

    plunkr demo #1

    https://www.firebase.com/docs/web/guide/understanding-data.html

    Friday, December 5, 2014

    client side reorder list

    I am looking into jquery ui drag and drop grid row

    http://jqueryui.com/sortable/

    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

    http://api.jqueryui.com/sortable/

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

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


    example : http://plnkr.co/edit/jpxc42tF55jktfI3upTE?p=preview 














    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


    Reference:
     content:://Authority/Path/id
    - 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,
    DATA_TABLE); 


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