Posts

Showing posts from June, 2020

Background Subtraction OpenCv Python

Image
Background Subtraction Background Subtraction is a method in image processing in which we subtract the background to detect the object or more specifically changes in the environment. We will create a python code with simple mathematical operations to create background subtraction. The way background subtraction work is we directly subtract background image from input image and then we binarize the image and after some operations like gaussian blur and erosion we get the object. Take 2 images, one background image and one with the object. The idea here is we are working with stable non movable camera. This type of camera are generally used for security.  Read the images in python using cv2.imread command then resize the images to desired size(resizing is always very helpful).  background = cv2.imread( 'background.jpg' ) image = cv2.imread( 'testforground.jpg' ) shape = ( 200 ,  200 ) bg = cv2.resize(background, shape) Convert t...

OpenCv Image Rotation

Image
OpenCV Image Rotation in Python We will learn how to rotate an image using python. This Technique is very helpful in data generation for computer vision tasks. Make sure you have OpenCV library installed in your python environment. Take an input image as shown below. Import libraries  Fig 1: Input image   import  numpy  as  np import  cv2, os, glob from  matplotlib  import  pyplot  as  plt   Here os and glob are used to find image path if required and matplot library is used for visualization. Read the file in python using cv2.imread('File path') command. The size of image can be large and to create standard we need to resize image to fix size so that we control the window size. Use cv2.resize(image, shape). Now use cv2.getRotationMatrix2D function and then affine transform to correctly rotate image. rot  = cv2.getRotationMatrix2D(center, angle ,  1.0 ) rotated_image = cv2.warpAffine...

Image Weather Classification

Image
CNN based weather classifier Convolutional Neural Network also known as CNN are of grate use when it comes to image data. They can be used to get both low level features and high level features. CNN are used in many places now and is future of robotics. uses of CNN Robotic Vision Biometric identification object detection and tracking Self Driving Car Object Identification We are going to classify weather images using Convolutional Neural Network.  This task can be performed in multiple ways and we are going to classify weather using regression network. The Network I have created is given below. python libraries required numpy os glob OpenCV Tensorflow keras Pands Matplotlib For weather classification problem download the dataset from link( link )   Dataset description number of images 1025 size of images variable labels are mentioned in the name of images number of labels 4 ['cloudy' , 'rain', 'shine', 'sunrise'] Create a file labelgenerator.py to genera...

Convolutional network based Classification

Image
CNN based weather classifier CNN(convolutional neural network) are very powerful Computation Weapon made by multiple mathematical processes. CNN can be used by robots to see environment through camera and understand the state of environment. A single layer of CNN works as a filter much like gaussian blur or edge detector filters and when they are used in multiple layers they can understand much  more than just color or shape, they can understand story of the image and today we are going to learn how to train a CNN to predict weather through image. Weather-CNN Before we start make sure you have tensorflow,keras,OpenCV, Matplotlib and pandas. we have to download dataset for wether images. Link to image dataset link(https://md-datasets-public-files-prod.s3.eu-west-1.amazonaws.com/64a54851-f95a-439d-aff7-3334a684e532) dataset consist of 1025 images of weather, it consist of 4 labels 'cloudy','rain','shine','sunrise', image shape varies. Import dataset, read ...

Opencv python object detection Tutorial (part 1)

Image
OpenCV Python  OpenCV Python hand Tracking Series(Part-1) There are many reasons to detect object using camera which allows system to interact with the environment. Detecting obstacles by self driving car(to avoid them of course:) Can be used in gripping object with robotic arm Servaliance Purpose or may be your professor asked you to do it :( we will use OpenCV python to detect human arm with basic image processing techniques. For this method we require OpenCV and numpy library. In this tutorial we will use color as feature and detect objects. For now we will detect a ball but shape does not matter as we are usingcolor as feature and not shape. There are multiple ways to perform the Task such as Color Feature Background Subtraction Shape Features Sift Features SURF Features Deep learning we will cover all the methods but for now we focus on color features. To start we take a good photo of object you want to Track like the image given below Now let's Start Coding, First import nump...

History of Reinforcement learning (IRL part-2)

History of Reinforcement Learning The early history of reinforcement learning has two main threads, both long and rich, that were pursued independently before intertwining in modern reinforcement learning. One thread concerns learning by trial and error, and originated in the psychology of animal learning. This thread runs through some of the earliest work in artificial intelligence and led to the revival of reinforcement learning in the early 1980s. The second thread concerns the problem of optimal control and its solution using value functions and dynamic programming. For the most part, this thread did not involve learning. The two threads were mostly independent, but became interrelated to some extent around a third, less distinct thread concerning temporal-di↵erence methods. All three threads came together in the late 1980s to produce the modern field of reinforcement learning. The thread focusing on trial-and-error learning is the one with which we are most familiar and about which ...

Introduction to Reinforcement Learning (Part-1)

Image
What is Reinforcement Learning? It is considered to be a part of machine learning in which the agent learn from experience. If you do not know what a agent is then for now consider it as a human child which interact with the environment. An agent keeps on performing task until it perfects the art of performing task. As we know Neural networks were designed to be similar to human brain computation method.  Similarly there are many methods in machine learning which come from human and there Psychology. The word 'Reinforcement' was first coined by Psychologist B.F. Skinner, according to him Reinforcement refer to anything that increases the likelihood that a response will occur. We can understand it from an example in life when we were kids and looked at fire through our eyes(sensors), which is a visual information of environment and a parameter of state and we want to find out about how it taste, can we eat it  as have any idea about what fire is and how it feels then we ha...