|
|
@@ -13,20 +13,8 @@ Usage: |
|
|
|
|
|
|
|
python peopleCounter.py -i PATH_TO_IMAGE # Reads and detect people in a single local stored image |
|
|
|
python peopleCounter.py -c # Attempts to detect people using webcam |
|
|
|
|
|
|
|
IMPORTANT: This example is given AS IT IS without any warranty |
|
|
|
|
|
|
|
Made by: Jose Garcia |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
URL_EDUCATIONAL = "http://things.ubidots.com" |
|
|
|
URL_INDUSTRIAL = "http://industrial.api.ubidots.com" |
|
|
|
INDUSTRIAL_USER = False # Set this to False if you are an educational user |
|
|
|
TOKEN = "A1E-VQSZw6exCjViKRfqHl7ISdrVEm3cG1" # Put here your Ubidots TOKEN |
|
|
|
DEVICE = "detector" # Device where will be stored the result |
|
|
|
VARIABLE = "people" # Variable where will be stored the result |
|
|
|
|
|
|
|
HOGCV = cv2.HOGDescriptor() |
|
|
|
HOGCV.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) |
|
|
|
|
|
|
@@ -56,26 +44,6 @@ def buildPayload(variable, value, context): |
|
|
|
return {variable: {"value": value, "context": context}} |
|
|
|
|
|
|
|
|
|
|
|
def sendToUbidots(token, device, variable, value, context={}, industrial=True): |
|
|
|
# Builds the endpoint |
|
|
|
url = URL_INDUSTRIAL if industrial else URL_EDUCATIONAL |
|
|
|
url = "{}/api/v1.6/devices/{}".format(url, device) |
|
|
|
|
|
|
|
payload = buildPayload(variable, value, context) |
|
|
|
headers = {"X-Auth-Token": token, "Content-Type": "application/json"} |
|
|
|
|
|
|
|
attempts = 0 |
|
|
|
status = 400 |
|
|
|
|
|
|
|
while status >= 400 and attempts <= 5: |
|
|
|
req = requests.post(url=url, headers=headers, json=payload) |
|
|
|
status = req.status_code |
|
|
|
attempts += 1 |
|
|
|
time.sleep(1) |
|
|
|
|
|
|
|
return req |
|
|
|
|
|
|
|
|
|
|
|
def argsParser(): |
|
|
|
ap = argparse.ArgumentParser() |
|
|
|
ap.add_argument("-i", "--image", default=None, |
|
|
@@ -93,12 +61,12 @@ def localDetect(image_path): |
|
|
|
image = imutils.resize(image, width=min(400, image.shape[1])) |
|
|
|
clone = image.copy() |
|
|
|
if len(image) <= 0: |
|
|
|
print("[ERROR] could not read your local image") |
|
|
|
print("[ERROR] could not read local image") |
|
|
|
return result |
|
|
|
print("[INFO] Detecting people") |
|
|
|
result = detector(image) |
|
|
|
|
|
|
|
# shows the result |
|
|
|
"""# shows the result |
|
|
|
for (xA, yA, xB, yB) in result: |
|
|
|
cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2) |
|
|
|
|
|
|
@@ -106,8 +74,8 @@ def localDetect(image_path): |
|
|
|
cv2.waitKey(0) |
|
|
|
cv2.destroyAllWindows() |
|
|
|
|
|
|
|
cv2.imwrite("result.png", np.hstack((clone, image))) |
|
|
|
return (result, image) |
|
|
|
cv2.imwrite("result.png", np.hstack((clone, image)))""" |
|
|
|
return result#(result, image) |
|
|
|
|
|
|
|
|
|
|
|
def cameraDetect(token, device, variable, sample_time=5): |