Skip to content

Commit

Permalink
Added more scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
alduxvm committed Mar 27, 2017
1 parent 9936acc commit 60c326b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
23 changes: 19 additions & 4 deletions car-detection-stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
#vehicle_classifier = cv2.CascadeClassifier('haars/cas4.xml') # from
#vehicle_classifier = cv2.CascadeClassifier('haars/cars2.xml') # from https://github.com/andrewssobral/vehicle_detection_haarcascades

record = True
if record:
fps = 10
capSize = (1200,675) # Size of video when is resized (original stream 1080x1920)
fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') # note the lower case
vout = cv2.VideoWriter()
success = vout.open('output.mov',fourcc,fps,capSize,True)

while True:
bytes += stream.read(1024)
a = bytes.find(b'\xff\xd8')
Expand All @@ -36,15 +44,22 @@
jpg = bytes[a:b+2]
bytes = bytes[b+2:]
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8), cv2.IMREAD_COLOR) # decode image
image = imutils.resize(i, width=min(600, i.shape[1])) # resize image (optional)
image = imutils.resize(i, width=min(1200, i.shape[1])) # resize image (optional)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

#vehicles = vehicle_classifier.detectMultiScale(gray, 1.1, 2, maxSize=(200,200))
vehicles = vehicle_classifier.detectMultiScale(gray, 1.1, 2)

vehicles = vehicle_classifier.detectMultiScale(gray, 1.1, 5)
print len(vehicles), 'vehicles found...'
for (x,y,w,h) in vehicles:
cv2.rectangle(image, (x,y), (x+w, y+h),(255,0,0),2)

cv2.imshow('frame', image)
if record:
vout.write(image)
if cv2.waitKey(1) == 27:
exit(0)
exit(0)

if record:
vout.release()
vout = None
cv2.destroyAllWindows()
2 changes: 2 additions & 0 deletions haar-detection-stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

# Source from http://212.170.22.153:8080/view/viewer_index.shtml?id=412 - test first in VLC
stream = urlopen('http://212.170.22.153:8080/mjpg/video.mjpg') # mjpg stream camera from an Axis network camera in Spain
#stream = urlopen('http://10.0.0.1:60152/liveview.JPG?%211234%21http%2dget%3a%2a%3aimage%2fjpeg%3a%2a%21%21%21%21%21') # qx10
bytes = bytes()

# Change to the haar as desired from what you want to test or use
#classifier = cv2.CascadeClassifier('haars/face.xml')
classifier = cv2.CascadeClassifier('haars/fullbody.xml')
#classifier = cv2.CascadeClassifier('haars/lowerbody.xml')
#classifier = cv2.CascadeClassifier('haars/upperbody.xml')
Expand Down
62 changes: 62 additions & 0 deletions people-detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python

"""people-detection.py: Detect cars from a web camera."""

__author__ = "Aldo Vargas"
__copyright__ = "Copyright 2017 Altax.net"

__license__ = "GPL"
__version__ = "1"
__maintainer__ = "Aldo Vargas"
__email__ = "alduxvm@gmail.com"
__status__ = "Development"

import numpy as np
import cv2
import imutils
from imutils.object_detection import non_max_suppression

cap = cv2.VideoCapture(0)
#cap = cv2.VideoCapture('video.mp4')

hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

record = False

if record:
fps = 15
capSize = (400,226) # this is the size of my source video
fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') # note the lower case
vout = cv2.VideoWriter()
success = vout.open('output.mov',fourcc,fps,capSize,True)

while(True):
ret, image = cap.read()

image = imutils.resize(image, width=min(400, image.shape[1]))
orig = image.copy()

(rects, weights) = hog.detectMultiScale(image, winStride=(4, 4),
padding=(8, 8), scale=1.05)

for (x, y, w, h) in rects:
cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255), 2)

rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)

for (xA, yA, xB, yB) in pick:
cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)

cv2.imshow('frame',image)
if record:
vout.write(image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
if record:
vout.release()
vout = None
cv2.destroyAllWindows()

0 comments on commit 60c326b

Please sign in to comment.