Browse Source

Merged streaming service in main

Errors with fps and image processing.
master
Georgios Gerontakis 5 years ago
parent
commit
4d7ac23ff8
  1. 68
      camera module/main.py
  2. BIN
      tracking and telemetry/Client/.vs/Client/v16/.suo
  3. BIN
      tracking and telemetry/Client/.vs/Client/v16/Server/sqlite3/storage.ide
  4. BIN
      tracking and telemetry/Client/obj/Debug/Client.csprojAssemblyReference.cache
  5. BIN
      tracking and telemetry/Client/obj/Debug/DesignTimeResolveAssemblyReferences.cache

68
camera module/main.py

@ -1,6 +1,9 @@
import cv2 import cv2
import base64
import zmq
# Constant variables definition. # Constant variables definition.
MAJOR_VERSION = cv2.getVersionMajor()
DESIRED_HEIGHT = 480 # The input image will be resized to this height, preserving its aspect ratio. DESIRED_HEIGHT = 480 # The input image will be resized to this height, preserving its aspect ratio.
BLUE_THRESHOLD = 150 # If the blue channel is bigger than this, it is considered background and removed. BLUE_THRESHOLD = 150 # If the blue channel is bigger than this, it is considered background and removed.
BINARY_THRESHOLD = 30 # If the pixel is not brighter than this, it is removed before detection. BINARY_THRESHOLD = 30 # If the pixel is not brighter than this, it is removed before detection.
@ -42,7 +45,10 @@ def removeColors(img):
blue[i,j,:] = 0 blue[i,j,:] = 0
gray = cv2.cvtColor(blue, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(blue, cv2.COLOR_BGR2GRAY)
_, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) if MAJOR_VERSION == 3:
_, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
else:
contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
if len(contours) > 0: if len(contours) > 0:
maxContour = max(contours, key = cv2.contourArea) maxContour = max(contours, key = cv2.contourArea)
x,y,w,h = cv2.boundingRect(maxContour) x,y,w,h = cv2.boundingRect(maxContour)
@ -55,12 +61,15 @@ def findMatchingContour(img, objX, objY):
dilated = img.copy() dilated = img.copy()
#dilated = cv2.dilate(img, (5,5), iterations=1) #dilated = cv2.dilate(img, (5,5), iterations=1)
canny = cv2.Canny(dilated, CANNY_LOW_THRES, CANNY_HIGH_THRES) canny = cv2.Canny(dilated, CANNY_LOW_THRES, CANNY_HIGH_THRES)
_, contours, hierarchy = cv2.findContours(canny, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE) if MAJOR_VERSION == 3:
_, contours, hierarchy = cv2.findContours(canny, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
else:
contours, hierarchy = cv2.findContours(canny, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
#print('len:' + str(len(contours))) #print('len:' + str(len(contours)))
contours.sort(key = cv2.contourArea, reverse = True) contours.sort(key = cv2.contourArea, reverse = True)
cv2.imshow('hey', canny) #cv2.imshow('hey', canny)
for i in range(len(contours)): for i in range(len(contours)):
contour = contours[i] contour = contours[i]
x,y,w,h = cv2.boundingRect(contour) x,y,w,h = cv2.boundingRect(contour)
@ -93,7 +102,10 @@ def processImage(img):
dilated = cv2.dilate(imgThres, (DILATION_KERNEL_SIZE,DILATION_KERNEL_SIZE), iterations=DILATION_ITERATIONS) dilated = cv2.dilate(imgThres, (DILATION_KERNEL_SIZE,DILATION_KERNEL_SIZE), iterations=DILATION_ITERATIONS)
# Find the largest image contour. # Find the largest image contour.
_, contours, hierarchy = cv2.findContours(dilated, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) if MAJOR_VERSION == 3:
_, contours, hierarchy = cv2.findContours(dilated, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
else:
contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
if len(contours) > 0: if len(contours) > 0:
maxContour = max(contours, key = cv2.contourArea) maxContour = max(contours, key = cv2.contourArea)
else: else:
@ -145,29 +157,41 @@ def determinateDir(cenX, cenY, objX, objY):
##################################################################################### #####################################################################################
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:4444")
while True:
client_ip = socket.recv()
break
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://' + client_ip.decode() + ':5555')
#camera = cv2.VideoCapture(0) # init the camera
cap = cv2.VideoCapture('/home/stelios/Desktop/drone_flight_test (cut).mp4')
cap = cv2.VideoCapture('C:/Users/Giorgos Ger/Desktop/drone_test.mp4')
if (cap.isOpened() == False): if (cap.isOpened() == False):
print('Error opening stream.') print('Error opening stream.')
quit() quit()
#cap.set(1, 30*6) #cap.set(1, 30*6)
while(cap.isOpened()): while (cap.isOpened()):
ret, frame = cap.read() try:
if (ret == True): ret, frame = cap.read()
img, xDir, yDir = processImage(frame) if (ret == True):
cv2.imshow('Frame', img) img, xDir, yDir = processImage(frame)
#cv2.imshow('Frame', img)
print('Got ' + str(xDir) + ' ' + str(yDir)) encoded, buffer = cv2.imencode('.jpg', img)
jpg_as_text = base64.b64encode(buffer)
k = cv2.waitKey(25) & 0xFF footage_socket.send(jpg_as_text)
if k == 27: cv2.waitKey(33)
else:
break break
if k == ord('p') or k == ord('P'): except KeyboardInterrupt:
cv2.waitKey(0) cap.release()
cv2.destroyAllWindows()
else: break
break
cap.release()
cv2.destroyAllWindows()

BIN
tracking and telemetry/Client/.vs/Client/v16/.suo

Binary file not shown.

BIN
tracking and telemetry/Client/.vs/Client/v16/Server/sqlite3/storage.ide

Binary file not shown.

BIN
tracking and telemetry/Client/obj/Debug/Client.csprojAssemblyReference.cache

Binary file not shown.

BIN
tracking and telemetry/Client/obj/Debug/DesignTimeResolveAssemblyReferences.cache

Binary file not shown.
Loading…
Cancel
Save