Jovian
⭐️
Sign In
In [1]:
import cv2
import os
import glob
import numpy as np
import time
import jovian
In [9]:
paths = glob.glob("C:\\Users\\vsneh\\Udemy-notebooks\\X_CLASSIFIER\\n1\\*")
#print(paths)
count = 0
for i in paths:
    count = count+1
    frame = cv2.imread(i)
    #frame = np.rot90(frame)
    #frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    cv2.resize(frame,(180,180))
    #cv2.imshow('test',frame)
    cv2.imwrite('C:\\Users\\vsneh\\Udemy-notebooks\\X_CLASSIFIER\\n\\%d.jpg'%count,frame)


In [7]:
import time
 
vidObj = cv2.VideoCapture("C:\\Users\\vsneh\\Udemy-notebooks\\pro_X_vid.mp4") 
count = 1
success = 1
  
while True: 
    success, image = vidObj.read()
    image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    image = np.rot90(image)
    cv2.resize(image,(180,180))
        # Saves the frames with frame-count 
    #time.sleep(0.7)
    cv2.imwrite('C:\\Users\\vsneh\\Udemy-notebooks\\X_CLASSIFIER\\p\\%d.jpg'%count, image) 
  
    count += 1
vidObj.release()
cv2.destroyAllWindows()
--------------------------------------------------------------------------- error Traceback (most recent call last) <ipython-input-7-b054b8014813> in <module> 7 while True: 8 success, image = vidObj.read() ----> 9 image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 10 image = np.rot90(image) 11 cv2.resize(image,(180,180)) error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
In [13]:
classifier = cv2.CascadeClassifier('C:/Users/vsneh/Udemy-notebooks/DATA/haarcascades/custom-hand-cascade.xml')
cap = cv2.VideoCapture(0)
while True:
    _,frame = cap.read()
    location = classifier.detectMultiScale(frame,scaleFactor = 1.3,minNeighbors = 1)
    for x,y,w,h in location:
        cv2.rectangle(frame,(x,y),(x+w,y+h),[0,255,0],6)
        cv2.imshow('Final Testing',frame)
    if(cv2.waitKey(1) == ord('q')):
        break
cap.release()
cv2.destroyAllWindows()
In [13]:
classifier = cv2.CascadeClassifier('C:/Users/vsneh/Udemy-notebooks/DATA/haarcascades/custom-hand-cascade.xml')
paths = glob.glob('C:/Users/vsneh/Udemy-notebooks/X_Pics/*')
count = 0
for i in paths:
    count = count+1
    img = cv2.imread(i)
    img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    img = cv2.resize(img,(180,180))
    cv2.imwrite('C:/Users/vsneh/Udemy-notebooks/X_Pics/%d.jpg'%count,img)
#img = cv2.imread('C:/Users/vsneh/Udemy-notebooks/X_Pics')
In [7]:
import kerasload_model
In [2]:
from keras.models import load_model
Using TensorFlow backend.
In [3]:
model = load_model('projectx.h5')
In [4]:
from keras.preprocessing import image
In [6]:
paths = glob.glob('C:/Users/vsneh/Udemy-notebooks/X_Pics/*')
count = 0
ls = []
for i in paths:
    img = image.load_img(i,target_size=(28,28))
    img = image.img_to_array(img)
    testing = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    testing = cv2.flip(testing,-1)
    k = model.predict_classes(testing.reshape(1,28,28,1))
    print(i,k)
    #img = img.reshape(1,28,28,1)
#print(ls) 
    cv2.imshow('test',testing)
    
C:/Users/vsneh/Udemy-notebooks/X_Pics\1.jpg [22] C:/Users/vsneh/Udemy-notebooks/X_Pics\10.jpg [5] C:/Users/vsneh/Udemy-notebooks/X_Pics\11.jpg [5] C:/Users/vsneh/Udemy-notebooks/X_Pics\12.jpg [11] C:/Users/vsneh/Udemy-notebooks/X_Pics\13.jpg [5] C:/Users/vsneh/Udemy-notebooks/X_Pics\14.jpg [8] C:/Users/vsneh/Udemy-notebooks/X_Pics\15.jpg [8] C:/Users/vsneh/Udemy-notebooks/X_Pics\16.jpg [3] C:/Users/vsneh/Udemy-notebooks/X_Pics\17.jpg [15] C:/Users/vsneh/Udemy-notebooks/X_Pics\2.jpg [5] C:/Users/vsneh/Udemy-notebooks/X_Pics\3.jpg [5] C:/Users/vsneh/Udemy-notebooks/X_Pics\4.jpg [11] C:/Users/vsneh/Udemy-notebooks/X_Pics\5.jpg [5] C:/Users/vsneh/Udemy-notebooks/X_Pics\6.jpg [8] C:/Users/vsneh/Udemy-notebooks/X_Pics\7.jpg [8] C:/Users/vsneh/Udemy-notebooks/X_Pics\8.jpg [3] C:/Users/vsneh/Udemy-notebooks/X_Pics\9.jpg [15]
In [18]:
img.shape
Out[18]:
(28, 28, 3)
In [27]:
cap = cv2.VideoCapture(0)
while True:
    ret,frames = cap.read()
    cv2.rectangle(frames,(100,100),(300,300),(255,0,0),3)
    frame = frames[100:300,100:300]
    cv2.imshow('frame',frames)
    if(cv2.waitKey(1)==ord('q')):
        break
cap.release()
cv2.destroyAllWindows()
In [13]:
cap = cv2.VideoCapture(0)
count = 0
while True:
    ret,frames = cap.read()
    cv2.rectangle(frames,(500,500),(500,500),(255,0,0),3)
    frame = frames[100:300,100:300]
    cv2.imshow('frame',frame)
    frame = cv2.flip(frame,2)
    #cv2.imwrite('C:\\Users\\vsneh\\Udemy-notebooks\\X_DATA\\%d.jpg'%count,frame)
    cv2.imshow('frame',frame)
    count = count+1
    if(cv2.waitKey(1)==ord('q')):
        break
cap.release()
cv2.destroyAllWindows()
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: