Last active
October 27, 2018 09:25
-
-
Save benjamintanweihao/bc935f6e426fd6837852812f93acc979 to your computer and use it in GitHub Desktop.
Getting instance and class segments from GTA V Gamehook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
benjamintanweihao
commented
Oct 27, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment