Friday, November 2, 2018

API fun

Rest lacked standards

in general an API has various “resources” that you access through “endpoints.” The endpoints give you access to the resource. (But terminology isn’t standard, so expect variety.

The endpoints indicate how you access the resource, and the method used with the endpoint indicates the allowed interactions (such as GET, POST, or DELETE) with the resource...Path parameters (represent them through curly braces) are part of the endpoint itself, and are not optional.

Parameters are options you can pass with the endpoint (such as specifying the response format or the amount returned) to influence the response. There are four types of parameters: header parameters, path parameters, query string parameters, and request body parameters

curl is a command-line utility that lets you execute HTTP requests with different parameters and methods. Instead of going to web resources in a browser’s address bar, you can use the command line to get these same resources, retrieved as text.

REST APIs follow an architectural style, not a specific standard. However, there are several REST specifications that have been developed to try to provide some standards about how REST APIs are described.

With OpenAPI (Swagger), instead of XML, you have set of JSON objects, with a specific schema that defines their naming, order, and contents. This JSON file (often expressed in YAML instead of JSON) describes each part of your API. By describing your API in a standard format, publishing tools can programmatically ingest the information about your API and display each component in a stylized, interactive display.

Swagger editor

YAML refers to “YAML Ain’t Markup Language,” is one of the code generators , but SmartBear who does SoapUI is supported.

display framework that reads an OpenAPI specification document and generates an interactive documentation website. This tutorial shows you how to use the Swagger UI interface and how to integrate an OpenAPI specification document into the standalone distribution of Swagger UI

The link for a good example

Or making a rest call using RestTemplate programatically:

For example, I did this project example and converted it to swaggerness and got json format with http://localhost:8080/v2/api-docs . Was able to get yaml with

Building a back-end API layer introduces a whole new area of challenges that goes beyond implementing just endpoints. You now have clients which will now be using your API. Your clients will need to know how to interact with your API. In SOAP-based web services, you had a WSDL to work with. This gave API developers an XML-based contract, which defined the API. However, with RESTFul web services, there is no WSDL. Thus your API documentation becomes more critical. API documentation should be structured so that it’s informative, succinct, and easy to read. But best practices on, how you document your API, its structure, what to include and what not to is altogether a different subject that I won’t be covering here"

API First Swagger Top Down approach
"There are a lot of good API design tools. Here are some useful comcparisons"

need to add spec for API. How can we do this in Apigee, do we have option to create swagger documentation for REST service in Apigee or we have to use other tool to prepare documentation and create spec in Apigee by importing doc created using third party tool, if documentation is out of box solution in Apigee. If Api documentation possible in Apigee. Please share how to implement this. using SmartDocs The tool you can use is

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