Posts

Showing posts from August, 2020

adaptive thresholding.

  import numpy as np import cv       img = cv . imread ( 'sudoku.png' , 0 ) _ , th1 = cv . threshold ( img , 127 , 255 , cv . THRESH_BINARY ) th2 = cv . adaptiveThreshold ( img , 255 , cv . ADAPTIVE_THRESH_MEAN_C , cv . THRESH_BINARY , 11 , 2 ) th3 = cv . adaptiveThreshold ( img , 255 , cv . ADAPTIVE_THRESH_GAUSSIAN_C , cv . THRESH_BINARY , 11 , 2 ) cv . imshow ( "Image" , img ) cv . imshow ( "THRESH_BINARY" , th1 ) cv . imshow ( "ADAPTIVE_THRESH_MEAN_C" , th2 ) cv . imshow ( "ADAPTIVE_THRESH_GAUSSIAN_C" , th3 ) cv . waitKey ( 0 ) cv . destroyAllWindows ()

cv2 trackbars-HSV IMAGES

  import cv2 import numpy as np def empty ( a ): pass def stackImages (scale , imgArray): rows = len (imgArray) cols = len (imgArray[ 0 ]) rowsAvailable = isinstance (imgArray[ 0 ] , list ) width = imgArray[ 0 ][ 0 ].shape[ 1 ] height = imgArray[ 0 ][ 0 ].shape[ 0 ] if rowsAvailable: for x in range ( 0 , rows): for y in range ( 0 , cols): if imgArray[x][y].shape[: 2 ] == imgArray[ 0 ][ 0 ].shape [: 2 ]: imgArray[x][y] = cv2.resize(imgArray[x][y] , ( 0 , 0 ) , None, scale , scale) else : imgArray[x][y] = cv2.resize(imgArray[x][y] , (imgArray[ 0 ][ 0 ].shape[ 1 ] , imgArray[ 0 ][ 0 ].shape[ 0 ]) , None, scale , scale) if len (imgArray[x][y].shape) == 2 : imgArray[x][y]= cv2.cvtColor( imgArray[x][y] , cv2.COLOR_GRAY2BGR) imageBlank = np.zeros((height , width , 3 ) , np.uint8) hor = [imageBlank]*rows hor_con = [imageBlank]*rows ...

starting cv2 and face recognition.

Image
import cv2  cap=cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') while True:     ret,frame=cap.read()     gray_frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)     if ret == False:         continue              faces=face_cascade.detectMultiScale(gray_frame,1.3,5)       for (x,y,w,h) in faces:         cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)     cv2.imshow("VideoFrame",frame)               key_pressed = cv2.waitKey(1) & 0xFF     if key_pressed == ord('q'):        break          cap.release() cv2.destroyAllWindows() ******************************designing opencv logo**************************** import cv2 import numpy as np #angles are measured clockwise img_=np.zeros((591,591,3)) c_c=(300,180) axes_len...

Code for diabitic patient-1.

 import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt x_train=pd.read_csv('Diabetes_XTrain.csv') y_train=pd.read_csv('Diabetes_YTrain.csv') x_test=pd.read_csv('Diabetes_Xtest.csv') data3=x_test.values data3.shape data1=x_train.values data2=y_train.values data1.shape def knn(query_x,data2,data1,k=15):     vals=[]     m=data1.shape[0]     for i in range(m):         val=np.sqrt(sum((query_x-data1[i])**2))         vals.append((val,data2[i]))              vals2=sorted(vals)     vals_=np.array(vals2[:k],dtype=object)     new_vals=np.unique(vals_[:,1],return_counts=True)     index=new_vals[1].argmax()     pred=new_vals[0][index]     return pred[0] n=data3.shape[0] final=[] for i in range(n):     f=knn(data3[i],data2,data1)     final.append(f)   final.insert(0,"Outcome") in...