Clean up project directory.
This commit is contained in:
@@ -1,79 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
Created on Thu Nov 22 14:16:46 2018
|
|
||||||
|
|
||||||
@author: pivatom
|
|
||||||
"""
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import cv2
|
|
||||||
|
|
||||||
img = cv2.imread('H:\car\GestureRecognition\IMG_0818.png', 1)
|
|
||||||
|
|
||||||
# Downscale the image
|
|
||||||
img = cv2.resize(img, None, fx=0.1, fy=0.1, interpolation = cv2.INTER_AREA)
|
|
||||||
|
|
||||||
min_seg_threshold = 1.2
|
|
||||||
max_seg_threshold = 1.8
|
|
||||||
|
|
||||||
# Need to make this get correct skin tones.
|
|
||||||
# img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
||||||
# img_gray[img_gray[:,:] > 90] = 255
|
|
||||||
# img_gray[img_gray[:,:] < 90] = 0
|
|
||||||
|
|
||||||
img_bin = np.zeros(shape=(img.shape[0], img.shape[1]), dtype=int)
|
|
||||||
img = np.where(img[:,:,1] == 0, 0, img[:,:,1])
|
|
||||||
img[(img[:,:,2]/img[:,:,1] > min_seg_threshold) & (img[:,:,2]/img[:,:,1] < max_seg_threshold)] = [255,255,255]
|
|
||||||
|
|
||||||
# Threshold to binary.
|
|
||||||
ret,img_thresh = cv2.threshold(img_bin, 127, 255, cv2.THRESH_BINARY)
|
|
||||||
|
|
||||||
# Following method is much faster -> 0.00143s
|
|
||||||
# Still want to speed up further by lowering reliance on memory, which is quite heavy..
|
|
||||||
k = np.sum(img_thresh) / 255
|
|
||||||
|
|
||||||
# Taking indices for num of rows.
|
|
||||||
x_ind = np.arange(0,img_thresh.shape[1])
|
|
||||||
y_ind = np.arange(0,img_thresh.shape[0])
|
|
||||||
coords = np.zeros((img_thresh.shape[0], img_thresh.shape[1], 2))
|
|
||||||
coords_x = np.zeros((img_thresh.shape[0], img_thresh.shape[1]))
|
|
||||||
coords_y = np.zeros((img_thresh.shape[0], img_thresh.shape[1]))
|
|
||||||
coords_x[:,:] = x_ind
|
|
||||||
|
|
||||||
|
|
||||||
# Even this is extremely quick as it goes through rows in the numpy array, which in python is much faster than columns
|
|
||||||
for element in y_ind:
|
|
||||||
coords_y[element,:] = element
|
|
||||||
|
|
||||||
# Now need to get the average x value and y value for centre of gravity
|
|
||||||
xb = int(np.sum(coords_x[img_thresh == 255])/k)
|
|
||||||
yb = int(np.sum(coords_y[img_thresh == 255])/k)
|
|
||||||
|
|
||||||
centre = (int(np.sum(coords_x[img_thresh == 255])/k), int(np.sum(coords_y[img_thresh == 255])/k))
|
|
||||||
|
|
||||||
#x,y,k,xb,yb = 0,0,0,0,0
|
|
||||||
#
|
|
||||||
## this is inherently slow...like very very slow...0.114s
|
|
||||||
#for pix in img_thresh:
|
|
||||||
# for j in pix:
|
|
||||||
# if j == 255:
|
|
||||||
# k += 1
|
|
||||||
# xb += x
|
|
||||||
# yb += y
|
|
||||||
# x += 1
|
|
||||||
# y += 1
|
|
||||||
# x = 0
|
|
||||||
#
|
|
||||||
#centre = (int(xb/k), int(yb/k))
|
|
||||||
|
|
||||||
|
|
||||||
cv2.rectangle(img_thresh, centre, (centre[0] + 20, centre[1] + 20), (0,0,255), 3)
|
|
||||||
cv2.circle(img_thresh, centre, 140, (0,0,0), 3)
|
|
||||||
|
|
||||||
# Now need to trace around the circle to figure out where the fingers are.
|
|
||||||
# First get equation of the circle:
|
|
||||||
# y = sart(r2 - (x-c)2 + c)
|
|
||||||
|
|
||||||
cv2.imshow("Binary-cot-out", img_thresh)
|
|
||||||
cv2.waitKey(0)
|
|
||||||
cv2.destroyAllWindows()
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import numpy as np
|
|
||||||
import cv2
|
|
||||||
|
|
||||||
img = cv2.imread('H:\car\GestureRecognition\IMG_0818.png', 1)
|
|
||||||
|
|
||||||
# Downscale the image
|
|
||||||
img = cv2.resize(img, None, fx=0.1, fy=0.1, interpolation = cv2.INTER_AREA)
|
|
||||||
|
|
||||||
min_seg_threshold = 1.2
|
|
||||||
max_seg_threshold = 3
|
|
||||||
|
|
||||||
# prevent divide by zero, by just forcing pixel to be ignored.
|
|
||||||
np.where(img[:,:,1] == 0, 0, img[:,:,1])
|
|
||||||
img[(img[:,:,2]/img[:,:,1] > min_seg_threshold) & (img[:,:,2]/img[:,:,1] < max_seg_threshold)] = [255,255,255]
|
|
||||||
|
|
||||||
# Try removing image noise.
|
|
||||||
#img = cv2.fastNlMeansDenoising(img)
|
|
||||||
|
|
||||||
cv2.imshow('image', img)
|
|
||||||
cv2.waitKey(0)
|
|
||||||
cv2.destroyAllWindows()
|
|
||||||
|
|
||||||
# Remove non-hand parts
|
|
||||||
|
|
||||||
# Find centre of the hand
|
|
||||||
# Hand parts are white pixels.
|
|
||||||
# Find sum of each col/row to find the left/rightmost and top/bottommost white pixels.
|
|
||||||
# Have used a for loop but obviously that is going to be slow.
|
|
||||||
|
|
||||||
# Draw appropriate circle
|
|
||||||
|
|
||||||
# Calculate number of different peaks.
|
|
||||||
# Article just traced around the circle and counted number of times switched from
|
|
||||||
# zero to one.
|
|
||||||
@@ -30,7 +30,7 @@ class SimpleHandRecogniser(HandRecogniser):
|
|||||||
|
|
||||||
# Apply another blur to rmeove any small holes/noise
|
# Apply another blur to rmeove any small holes/noise
|
||||||
self.img_cut = self.__denoise(self.img_cut)
|
self.img_cut = self.__denoise(self.img_cut)
|
||||||
ret, self.img_cut = cv2.threshold(self.img_cut, 50, 255, cv2.THRESH_BINARY)
|
_, self.img_cut = cv2.threshold(self.img_cut, 50, 255, cv2.THRESH_BINARY)
|
||||||
|
|
||||||
def __denoise(self, image):
|
def __denoise(self, image):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
# This program will let you test your ESC and brushless motor.
|
|
||||||
# Make sure your battery is not connected if you are going to calibrate it at first.
|
|
||||||
# Since you are testing your motor, I hope you don't have your propeller attached to it otherwise you are in trouble my friend...?
|
|
||||||
# This program is made by AGT @instructable.com. DO NOT REPUBLISH THIS PROGRAM... actually the program itself is harmful pssst Its not, its safe.
|
|
||||||
|
|
||||||
import os #importing os library so as to communicate with the system
|
|
||||||
import time #importing time library to make Rpi wait because its too impatient
|
|
||||||
os.system ("sudo pigpiod") #Launching GPIO library, will say it can't connect if already running
|
|
||||||
time.sleep(1) # As i said it is too impatient and so if this delay is removed you will get an error
|
|
||||||
import pigpio #importing GPIO library
|
|
||||||
|
|
||||||
ESC=19 #Connect the ESC in this GPIO pin
|
|
||||||
|
|
||||||
pi = pigpio.pi();
|
|
||||||
pi.set_servo_pulsewidth(ESC, 0)
|
|
||||||
|
|
||||||
max_value = 2000 #change this if your ESC's max value is different or leave it be
|
|
||||||
min_value = 1000 #change this if your ESC's min value is different or leave it be
|
|
||||||
print("For first time launch, select calibrate")
|
|
||||||
print("Type the exact word for the function you want")
|
|
||||||
print("calibrate OR manual OR control OR arm OR stop")
|
|
||||||
|
|
||||||
def manual_drive(): #You will use this function to program your ESC if required
|
|
||||||
print("You have selected manual option so give a value between 0 and you max value")
|
|
||||||
while True:
|
|
||||||
inp = input()
|
|
||||||
if inp == "stop":
|
|
||||||
stop()
|
|
||||||
break
|
|
||||||
elif inp == "control":
|
|
||||||
control()
|
|
||||||
break
|
|
||||||
elif inp == "arm":
|
|
||||||
arm()
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
pi.set_servo_pulsewidth(ESC,inp)
|
|
||||||
|
|
||||||
def calibrate(): #This is the auto calibration procedure of a normal ESC
|
|
||||||
pi.set_servo_pulsewidth(ESC, 0)
|
|
||||||
print("Disconnect the battery and press Enter")
|
|
||||||
inp = input()
|
|
||||||
if inp == '':
|
|
||||||
pi.set_servo_pulsewidth(ESC, max_value)
|
|
||||||
print("Connect the battery NOW.. you will here two beeps, then wait for a gradual falling tone then press Enter")
|
|
||||||
inp = input()
|
|
||||||
if inp == '':
|
|
||||||
pi.set_servo_pulsewidth(ESC, min_value)
|
|
||||||
print("Wierd eh! Special tone")
|
|
||||||
time.sleep(7)
|
|
||||||
print("Wait for it ....")
|
|
||||||
time.sleep (5)
|
|
||||||
print("Im working on it, DONT WORRY JUST WAIT.....")
|
|
||||||
pi.set_servo_pulsewidth(ESC, 0)
|
|
||||||
time.sleep(2)
|
|
||||||
print("Arming ESC now...")
|
|
||||||
pi.set_servo_pulsewidth(ESC, min_value)
|
|
||||||
time.sleep(1)
|
|
||||||
print("See.... uhhhhh")
|
|
||||||
control() # You can change this to any other function you want
|
|
||||||
|
|
||||||
def control():
|
|
||||||
print("I'm Starting the motor, I hope its calibrated and armed, if not restart by giving 'x'")
|
|
||||||
time.sleep(1)
|
|
||||||
speed = 1500 # change your speed if you want to.... it should be between 700 - 2000
|
|
||||||
print("Controls - a to decrease speed & d to increase speed OR q to decrease a lot of speed & e to increase a lot of speed")
|
|
||||||
while True:
|
|
||||||
pi.set_servo_pulsewidth(ESC, speed)
|
|
||||||
inp = input()
|
|
||||||
|
|
||||||
if inp == "q":
|
|
||||||
speed -= 100 # decrementing the speed like hell
|
|
||||||
print("speed = %d" % speed)
|
|
||||||
elif inp == "e":
|
|
||||||
speed += 100 # incrementing the speed like hell
|
|
||||||
print("speed = %d" % speed)
|
|
||||||
elif inp == "d":
|
|
||||||
speed += 10 # incrementing the speed
|
|
||||||
print("speed = %d" % speed)
|
|
||||||
elif inp == "a":
|
|
||||||
speed -= 10 # decrementing the speed
|
|
||||||
print("speed = %d" % speed)
|
|
||||||
elif inp == "stop":
|
|
||||||
stop() #going for the stop function
|
|
||||||
break
|
|
||||||
elif inp == "manual":
|
|
||||||
manual_drive()
|
|
||||||
break
|
|
||||||
elif inp == "arm":
|
|
||||||
arm()
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print("WHAT DID I SAID!! Press a,q,d or e")
|
|
||||||
|
|
||||||
def arm(): #This is the arming procedure of an ESC
|
|
||||||
print("Connect the battery and press Enter")
|
|
||||||
inp = input()
|
|
||||||
if inp == '':
|
|
||||||
pi.set_servo_pulsewidth(ESC, 0)
|
|
||||||
time.sleep(1)
|
|
||||||
pi.set_servo_pulsewidth(ESC, max_value)
|
|
||||||
time.sleep(1)
|
|
||||||
pi.set_servo_pulsewidth(ESC, min_value)
|
|
||||||
time.sleep(1)
|
|
||||||
control()
|
|
||||||
|
|
||||||
def stop(): #This will stop every action your Pi is performing for ESC ofcourse.
|
|
||||||
pi.set_servo_pulsewidth(ESC, 0)
|
|
||||||
pi.stop()
|
|
||||||
|
|
||||||
#This is the start of the program actually, to start the function it needs to be initialized before calling... stupid python.
|
|
||||||
inp = input()
|
|
||||||
if inp == "manual":
|
|
||||||
manual_drive()
|
|
||||||
elif inp == "calibrate":
|
|
||||||
calibrate()
|
|
||||||
elif inp == "arm":
|
|
||||||
arm()
|
|
||||||
elif inp == "control":
|
|
||||||
control()
|
|
||||||
elif inp == "stop":
|
|
||||||
stop()
|
|
||||||
else:
|
|
||||||
print("Thank You for not following the things I'm saying... now you gotta restart the program STUPID!!")
|
|
||||||
0
MotorControl/gpiozero/__init__.py
Normal file
0
MotorControl/gpiozero/__init__.py
Normal file
@@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
from gpiozero import Servo, Device
|
from gpiozero import Servo, Device
|
||||||
from gpiozero.pins.pigpio import PiGPIOFactory
|
from gpiozero.pins.pigpio import PiGPIOFactory
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|||||||
0
persontracking/__init__.py
Normal file
0
persontracking/__init__.py
Normal file
@@ -1,7 +1,8 @@
|
|||||||
import rplidar
|
import rplidar
|
||||||
from rplidar import RPLidar
|
from rplidar import RPLidar
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import algorithms
|
from persontracking import algorithms
|
||||||
|
import zmq
|
||||||
|
|
||||||
class LidarCache():
|
class LidarCache():
|
||||||
'''
|
'''
|
||||||
@@ -14,7 +15,8 @@ class LidarCache():
|
|||||||
currentGroups = None
|
currentGroups = None
|
||||||
groupsChanged = []
|
groupsChanged = []
|
||||||
|
|
||||||
def __init__(self, measurements=100):
|
def __init__(self, port, measurements=100):
|
||||||
|
self.port = port
|
||||||
self.lidar = RPLidar('/dev/ttyUSB0')
|
self.lidar = RPLidar('/dev/ttyUSB0')
|
||||||
self.measurements = measurements
|
self.measurements = measurements
|
||||||
print('Info: ' + self.lidar.get_info())
|
print('Info: ' + self.lidar.get_info())
|
||||||
@@ -28,6 +30,11 @@ class LidarCache():
|
|||||||
'''
|
'''
|
||||||
Performs a scan for the given number of iterations.
|
Performs a scan for the given number of iterations.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# Create the 0MQ socket first. This should not be passed between threads.
|
||||||
|
self._socket = self._create_socket()
|
||||||
|
self._socket.bind("tcp://*:" + str(self.port))
|
||||||
|
|
||||||
for i, scan in enumerate(self.lidar.iter_scans(min_len=self.measurements)):
|
for i, scan in enumerate(self.lidar.iter_scans(min_len=self.measurements)):
|
||||||
print('%d: Got %d measurments' % (i, len(scan)))
|
print('%d: Got %d measurments' % (i, len(scan)))
|
||||||
if(not self.run):
|
if(not self.run):
|
||||||
@@ -40,7 +47,13 @@ class LidarCache():
|
|||||||
self.currentGroups = algorithms.calc_groups(scan)
|
self.currentGroups = algorithms.calc_groups(scan)
|
||||||
|
|
||||||
def fireGroupsChanged(self):
|
def fireGroupsChanged(self):
|
||||||
|
# Send the updated groups to 0MQ socket.
|
||||||
|
# self._socket.send_multipart(["lidar_map", ...])
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stop_scanning(self):
|
def stop_scanning(self):
|
||||||
self.run = False
|
self.run = False
|
||||||
|
|
||||||
|
def _create_socket(self):
|
||||||
|
return zmq.Context.instance().socket(zmq.PUB)
|
||||||
|
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import lidar_tracker_pb2
|
import persontracking.lidar_tracker_pb2 as lidar_tracker_pb2
|
||||||
import lidar_tracker_pb2_grpc
|
from persontracking.lidar_tracker_pb2_grpc import PersonTrackingServicer
|
||||||
from .lidar_cache import LidarCache
|
from persontracking.lidar_cache import LidarCache\
|
||||||
class LidarServicer(lidar_tracker_pb2_grpc.PersonTrackingServicer):
|
|
||||||
|
|
||||||
|
|
||||||
|
class LidarServicer(PersonTrackingServicer):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cache = LidarCache(measurements=100)
|
self.cache = LidarCache(measurements=100)
|
||||||
@@ -22,4 +25,3 @@ class LidarServicer(lidar_tracker_pb2_grpc.PersonTrackingServicer):
|
|||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ message PointScan{
|
|||||||
repeated Point points = 1;
|
repeated Point points = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message TrackingInfo{
|
||||||
|
int32 port = 1;
|
||||||
|
}
|
||||||
|
|
||||||
service PersonTracking{
|
service PersonTracking{
|
||||||
rpc set_tracking_group(Int32Value) returns (Empty) {}
|
rpc set_tracking_group(Int32Value) returns (Empty) {}
|
||||||
|
|
||||||
@@ -31,5 +35,5 @@ service PersonTracking{
|
|||||||
|
|
||||||
rpc get_scan_data(Empty) returns (PointScan) {}
|
rpc get_scan_data(Empty) returns (PointScan) {}
|
||||||
|
|
||||||
rpc start_tracking(Empty) returns (Empty) {}
|
rpc start_tracking(TrackingInfo) returns (Empty) {}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user