Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import logging as log
- import matplotlib.pyplot as plt
- from PIL import Image
- import numpy as np
- import tensorflow as tf
- import cv2
- import re
- import tqdm
- import keras
- from keras.layers import Dense, Conv2D, Dropout, MaxPooling2D, Flatten
- from keras.models import Sequential,load_model
- from keras.callbacks import ModelCheckpoint,EarlyStopping, TensorBoard
- video = cv2.VideoCapture(1)
- while True:
- X_test = []
- flag,frame = video.read()
- #image = cv2.imread('/home/tpemist/Desktop/visualtest/train/info/0001_0010_0035_0054_0054.jpg')
- show = cv2.resize(frame,(640,480))
- image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- image = cv2.resize(image,(128,96))
- nparr = np.array(image) / 255.0
- X_test.append(nparr)
- X_test = np.array(X_test, dtype=np.float32)
- X_test = X_test.reshape(X_test.shape[0], 96, 128, 1)
- model = Sequential()
- model.add(Conv2D(32, (3, 3),padding = 'same', activation = 'relu', input_shape = (96,128,1)))
- model.add(MaxPooling2D((2,2)))
- model.add(Dropout(0.5))
- model.add(Conv2D(32, (3, 3),padding = 'same', activation = 'relu'))
- model.add(Conv2D(32, (3, 3),padding = 'same', activation = 'relu'))
- model.add(MaxPooling2D((2,2)))
- model.add(Dropout(0.5))
- model.add(Conv2D(32, (3, 3),padding = 'same', activation = 'relu'))
- model.add(MaxPooling2D((2,2)))
- model.add(Dropout(0.75))
- model.add(Flatten())
- model.add(Dense(200))
- model.add(Dropout(0.5))
- model.add(Dense(200))
- model.add(Dropout(0.5))
- model.add(Dense(3))
- X_test = np.array(X_test)
- model.load_weights('train_model2')
- location = model.predict(X_test)
- location = location.astype(np.float32)
- x = (location[0])[0]
- y = (location[0])[1]
- w = (location[0])[2]
- #print x,y,w
- x1 = int((x*5+(x-1)*5)/2)
- y2 = int((y*5+(y-1)*5)/2)
- w2 = int(w*2.5)
- #print x1,y2,w2
- cv2.rectangle(show, (x1,y2), (x1+w2, y2+w2), (255, 255, 255), 2)
- cv2.imshow('Video', show)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- video.release()
- cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment