Skip to content

Instantly share code, notes, and snippets.

@nithikan
Created April 18, 2018 09:30
Show Gist options
  • Save nithikan/2996f4926dbc09de59794d6862a14cc6 to your computer and use it in GitHub Desktop.
Save nithikan/2996f4926dbc09de59794d6862a14cc6 to your computer and use it in GitHub Desktop.
##### Exercise 5 Read an image from UCF Crowd dataset and draw lines between people.
##### Lines are between a person and 10 of the most far people from that person.
##### 18/04/2018
##### Nithikan Srinakrung - Bam
##### DFL, FTSM, UKM
import cv2
import scipy.io as sio
import numpy as np
from numpy.matlib import repmat
img = cv2.imread("D:\\Coop\\UCF_CC_50\\50.jpg")
data = sio.loadmat("D:\\Coop\\UCF_CC_50\\50_ann.mat")
ann = data["annPoints"]
lowest = 0
highest = len(ann)-1
print (highest)
index = np.random.randint(lowest,highest)
print (index)
person = ann[index]
print (person)
a = repmat(person,data["annPoints"].shape[0],1)
distances = (a - data["annPoints"])**2
distances = np.sum(distances, axis =1)
distances = np.sqrt(distances)
indices = np.argsort(distances)
print(ann[indices][-10:])
for p in ann[indices][-90:]:
line_img = cv2.line(img,(int(person[0]),int(person[1])),(int(p[0]),int(p[1])),(0,0,255),thickness=2,lineType=8, shift=0)
cv2.imshow("far away", img)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment