-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
259 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import argparse | ||
from skimage.feature import hog | ||
import numpy as np | ||
import os | ||
import cv2 | ||
import json | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('in_dir', type=str) | ||
parser.add_argument('out_file', type=str) | ||
|
||
args = parser.parse_args() | ||
|
||
data = {} | ||
for cat_name in sorted(os.listdir(args.in_dir)): | ||
cat_path = os.path.join(args.in_dir, cat_name) | ||
if not os.path.isdir(cat_path): | ||
continue | ||
|
||
data_chara = [] | ||
for in_file in sorted(os.listdir(cat_path)): | ||
in_path = os.path.join(cat_path, in_file) | ||
img = cv2.imread(in_path, 0) # grayscale | ||
# img = cv2.resize(img, (110, 110)) | ||
ft = hog(img) | ||
data_chara.append(ft.tolist()) | ||
|
||
data[cat_name] = data_chara | ||
|
||
os.makedirs(os.path.dirname(args.out_file), exist_ok=True) | ||
with open(args.out_file, 'w') as fp: | ||
json.dump(data, fp) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import argparse | ||
from skimage.feature import hog | ||
import numpy as np | ||
import os | ||
import cv2 | ||
import json | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('in_dir', type=str) | ||
parser.add_argument('out_file', type=str) | ||
|
||
args = parser.parse_args() | ||
|
||
data = {} | ||
for cat_name in sorted(os.listdir(args.in_dir)): | ||
cat_path = os.path.join(args.in_dir, cat_name) | ||
if not os.path.isdir(cat_path): | ||
continue | ||
|
||
digit = int(cat_name) | ||
print(digit) | ||
|
||
data_digit = [] | ||
for in_file in sorted(os.listdir(cat_path)): | ||
in_path = os.path.join(cat_path, in_file) | ||
img = cv2.imread(in_path, 0) # grayscale | ||
img = cv2.resize(img, (35, 55)) | ||
ft = hog(img) | ||
data_digit.append(ft.tolist()) | ||
|
||
data[digit] = data_digit | ||
|
||
os.makedirs(os.path.dirname(args.out_file), exist_ok=True) | ||
with open(args.out_file, 'w') as fp: | ||
json.dump(data, fp) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import argparse | ||
from skimage.feature import hog | ||
import numpy as np | ||
import os | ||
import cv2 | ||
import json | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('in_dir', type=str) | ||
parser.add_argument('out_file', type=str) | ||
|
||
args = parser.parse_args() | ||
|
||
data = {} | ||
for cat_name in sorted(os.listdir(args.in_dir)): | ||
cat_path = os.path.join(args.in_dir, cat_name) | ||
if not os.path.isdir(cat_path): | ||
continue | ||
|
||
data_chara = [] | ||
for in_file in sorted(os.listdir(cat_path)): | ||
in_path = os.path.join(cat_path, in_file) | ||
img = cv2.imread(in_path, 0) # grayscale | ||
img = cv2.resize(img, (30, 30)) | ||
ft = hog(img) | ||
data_chara.append(ft.tolist()) | ||
|
||
data[cat_name] = data_chara | ||
|
||
os.makedirs(os.path.dirname(args.out_file), exist_ok=True) | ||
with open(args.out_file, 'w') as fp: | ||
json.dump(data, fp) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import cv2 | ||
import argparse | ||
from PIL import Image | ||
import os | ||
import numpy as np | ||
import SSBUBoundingBoxUtil | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('in_file', type=str) | ||
parser.add_argument('out_dir', type=str) | ||
parser.add_argument('fighter_num', type=int) | ||
args = parser.parse_args() | ||
|
||
|
||
os.makedirs(args.out_dir, exist_ok=True) | ||
|
||
frame_files = None | ||
cap = None | ||
if os.path.isdir(args.in_file): | ||
frame_files = [ os.path.join(args.in_file, file) for file in os.listdir(args.in_file) ] | ||
else: | ||
cap = cv2.VideoCapture(args.in_file) | ||
|
||
frame_idx = 0 | ||
def next_frame(): | ||
global frame_idx | ||
|
||
if frame_files is not None: | ||
if len(frame_files) <= frame_idx: | ||
return None | ||
frame = cv2.imread(frame_files[frame_idx]) | ||
else: | ||
ret, frame = cap.read() | ||
|
||
frame_idx += 1 | ||
return frame | ||
|
||
in_file = os.path.basename(args.in_file) | ||
|
||
while True: | ||
img = next_frame() | ||
if img is None: | ||
break | ||
|
||
bboxes = SSBUBoundingBoxUtil.fighters_chara_bbox(args.fighter_num) | ||
for fighter_idx in range(len(bboxes)): | ||
# if fighter_idx != 3: | ||
# continue | ||
bbox = bboxes[fighter_idx] | ||
chara = img[bbox[1]:bbox[1]+bbox[3], bbox[0]:bbox[0]+bbox[2]] | ||
|
||
file = '%s-f%d-%d.png' % (in_file, fighter_idx, frame_idx, ) | ||
path = os.path.join(args.out_dir, file) | ||
cv2.imwrite(path, chara) | ||
|
||
print(frame_idx, fighter_idx) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import cv2 | ||
import argparse | ||
from PIL import Image | ||
import os | ||
import numpy as np | ||
import SSBUBoundingBoxUtil | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('in_file', type=str) | ||
parser.add_argument('out_dir', type=str) | ||
parser.add_argument('fighter_num', type=int) | ||
args = parser.parse_args() | ||
|
||
|
||
os.makedirs(args.out_dir, exist_ok=True) | ||
|
||
|
||
frame_files = None | ||
cap = None | ||
if os.path.isdir(args.in_file): | ||
frame_files = [ os.path.join(args.in_file, file) for file in os.listdir(args.in_file) ] | ||
else: | ||
cap = cv2.VideoCapture(args.in_file) | ||
|
||
frame_idx = 0 | ||
def next_frame(): | ||
global frame_idx | ||
|
||
if frame_files is not None: | ||
if len(frame_files) <= frame_idx: | ||
return None | ||
frame = cv2.imread(frame_files[frame_idx]) | ||
else: | ||
ret, frame = cap.read() | ||
|
||
frame_idx += 1 | ||
return frame | ||
|
||
in_file = os.path.basename(args.in_file) | ||
|
||
fighters_stock_bboxes = SSBUBoundingBoxUtil.fighters_stock_bboxes(args.fighter_num, stock_num=3) | ||
|
||
while True: | ||
img = next_frame() | ||
if img is None: | ||
break | ||
|
||
for fighter_idx, bboxes in enumerate(fighters_stock_bboxes): | ||
for idx in range(len(bboxes)): | ||
# if idx != 3: | ||
# continue | ||
bbox = bboxes[idx] | ||
chara = img[bbox[1]:bbox[1]+bbox[3], bbox[0]:bbox[0]+bbox[2]] | ||
|
||
file = '%s-f%d-s%d-%d.png' % (in_file, fighter_idx, idx, frame_idx, ) | ||
path = os.path.join(args.out_dir, file) | ||
cv2.imwrite(path, chara) | ||
|
||
print(frame_idx, fighter_idx) |
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