Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Last active October 27, 2018 09:25
Show Gist options
  • Save benjamintanweihao/bc935f6e426fd6837852812f93acc979 to your computer and use it in GitHub Desktop.
Save benjamintanweihao/bc935f6e426fd6837852812f93acc979 to your computer and use it in GitHub Desktop.
Getting instance and class segments from GTA V Gamehook
import numpy as np
import matplotlib.pyplot as plt
filename = 'C:\\Users\\Benjamin Tan\\Desktop\\00016351_object_id.raw'
vals = np.linspace(0,1,256)
np.random.shuffle(vals)
cmap = plt.cm.colors.ListedColormap(plt.cm.jet(vals))
# Load the object_id.raw file and skip the first 4 bytes
A = np.fromfile(filename, dtype='int32', sep='')[4:]
A = A.reshape([600, 800])
# shifting the bits to differentiate the segments
B = A & ((1<<28)-1)
# This shows instance segments
plt.imshow(B, cmap=cmap); plt.show()
# shifting the bits to get the class labels
C = ((A >> 28) & 0xf)
# >>> print(set(x for x in B.reshape(-1)))
# {0, 1, 2, 3} <- class labels
plt.imshow(C, cmap=cmap); plt.show()
@benjamintanweihao
Copy link
Author

instance
class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment