Monday, 25 November 2019

polygon-shape-counting

polygon-shape-counting:

Input Image: 




Output Image:









Code :
Main code 1 :

import cv2
import numpy as np
import os

im = cv2.imread('input1.jpg')


imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)

ret, thresh = cv2.threshold(imgray, 220, 255, 0)
edges = cv2.Canny(thresh,150,180,apertureSize = 3)

ret, labels = cv2.connectedComponents(~thresh)

x=0

[m,n]=np.shape(thresh)


c=1
cwd = os.getcwd()
msk=np.zeros(np.shape(thresh))
while c
    msk=np.zeros(np.shape(thresh))
    msk[(labels==c)]=[255]
    msk=np.array(msk,dtype=np.uint8)
    msk_img=str(c)+'.jpg'
    filename = os.path.join(cwd, msk_img)
    cv2.imwrite(filename,msk)
    c=c+1

print("Total Polygon Objects ", c)



Code 2 :

Main code 2:

import cv2
import numpy as np
import os
im = cv2.imread('input1.jpg')


imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)

ret, thresh = cv2.threshold(imgray, 220, 255, 0)
edges = cv2.Canny(thresh,150,180,apertureSize = 3)

ret, labels = cv2.connectedComponents(~thresh)

x=0

[m,n]=np.shape(thresh)


c=1
cwd = os.getcwd()
msk=np.zeros(np.shape(thresh))
while c    msk=np.zeros(np.shape(thresh))
    msk[(labels==c)]=[255]
    msk=np.array(msk,dtype=np.uint8)
    edges = cv2.Canny(msk,150,180,apertureSize = 3)
    image2, contours, _ = cv2.findContours(edges    , cv2.CHAIN_APPROX_NONE, cv2.CHAIN_APPROX_SIMPLE)
    cnt=contours[-1]
    msk_img=str(c)+'.jpg'
    filename = os.path.join(cwd, msk_img)

    ## Objects side detection using controus and defects
    ## Objets sides are mentioned red color marker
    import obj_sid
    # obj_sid.sides(cnt,im)
    obj_sid.equl_side(cnt,im,msk,filename)
    cv2.namedWindow('image contours', cv2.WINDOW_GUI_NORMAL)
    cv2.drawContours(im, contours[-1],-1, (0, 255, 0), 3)
    cv2.imshow('image contours',im)
    cv2.waitKey(0)



 
    # cv2.imwrite(filename,msk)
    c=c+1
print("Total Polygon Objects ", c)



Function code:

import cv2
import numpy as np
import os
im = cv2.imread('input1.jpg')


imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)

ret, thresh = cv2.threshold(imgray, 220, 255, 0)
edges = cv2.Canny(thresh,150,180,apertureSize = 3)

ret, labels = cv2.connectedComponents(~thresh)

x=0

[m,n]=np.shape(thresh)


c=1
cwd = os.getcwd()
msk=np.zeros(np.shape(thresh))
while c    msk=np.zeros(np.shape(thresh))
    msk[(labels==c)]=[255]
    msk=np.array(msk,dtype=np.uint8)
    edges = cv2.Canny(msk,150,180,apertureSize = 3)
    image2, contours, _ = cv2.findContours(edges    , cv2.CHAIN_APPROX_NONE, cv2.CHAIN_APPROX_SIMPLE)
    cnt=contours[-1]
    msk_img=str(c)+'.jpg'
    filename = os.path.join(cwd, msk_img)

    ## Objects side detection using controus and defects
    ## Objets sides are mentioned red color marker
    import obj_sid
    # obj_sid.sides(cnt,im)
    obj_sid.equl_side(cnt,im,msk,filename)
    cv2.namedWindow('image contours', cv2.WINDOW_GUI_NORMAL)
    cv2.drawContours(im, contours[-1],-1, (0, 255, 0), 3)
    cv2.imshow('image contours',im)
    cv2.waitKey(0)



 
    # cv2.imwrite(filename,msk)
    c=c+1
print("Total Polygon Objects ", c)


















Wednesday, 29 May 2019

Saturday, 23 February 2019

Automatic mail Generation from MATLAB

Automaticmail:

[mail,password]=mailpass()
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
% Send the email.  Note that the first input is the address you are sending the email to
sendmail(mail,'Test from SELVA','Hello! This is a test from SELVA!')

Automaticmail

Sunday, 17 June 2018

OpenCV C++ Image Splitting:



#include  <opencv2/opencv.hpp>
#include  <opencv2/imgproc/imgproc.hpp>
//#include <opencv2/highgui/highgui.hpp>
#include <iostream>
//#include <iostream>
//#include <opencv2/imgcodecs/imgcodecs.hpp>
//using namespace std;
using namespace cv;
using namespace std;


int main()
{
Mat image;
image=imread("appa.jpg",CV_LOAD_IMAGE_ANYCOLOR);
Mat r, g, b;
r=image;
// splitting
Mat src;
vector<Mat> rgbChannels(3);
split(src,rgbChannels);
Mat fin_img;
g=Mat::zeros(Size(image.cols,image.rows),CV_8UC1);
{

vector<Mat>channels;
channels.push_back(g);
//channels.push_back(g);
//channels.push_back(rgbChannels[2]);
merge(channels,fin_img);
namedWindow("Green",1);
imshow("Green",fin_img);
}
imshow("Image_input",image);
waitKey(0);

//waitKey(0);
destroyAllWindows();



}