forked from w102060018w/Nature-Cut-Out
-
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
PO intern
committed
Aug 8, 2017
1 parent
e4f329c
commit 473e1c7
Showing
16 changed files
with
7,756 additions
and
57 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
987 changes: 987 additions & 0 deletions
987
testing/python/.ipynb_checkpoints/demo_testing-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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,123 @@ | ||
''' | ||
author : Sean Gillies | ||
edit : Winnie Hong | ||
create date : 0714/2017 | ||
''' | ||
|
||
import sys | ||
sys.path.append('/Users/pointern/.virtualenvs/cv3/lib/python3.6/site-packages') | ||
|
||
from scipy.spatial import Delaunay | ||
from descartes import PolygonPatch | ||
|
||
from matplotlib.collections import LineCollection | ||
from shapely.ops import cascaded_union, polygonize | ||
from shapely.geometry import MultiLineString | ||
import shapely.geometry as geometry | ||
import math | ||
import numpy as np | ||
|
||
import matplotlib as mpl | ||
mpl.use('TkAgg') | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
|
||
#import cv2 | ||
|
||
|
||
def add_edge(edges,edge_points, coords, i, j): | ||
""" | ||
Add a line between the i-th and j-th points, | ||
if not in the list already | ||
""" | ||
if (i, j) in edges or (j, i) in edges: | ||
# already added | ||
return | ||
|
||
# print((i,j)) | ||
edges.add( (i, j) ) | ||
edge_points.append(coords[ [i, j] ]) | ||
|
||
# print(edges) | ||
# print(edge_points) | ||
|
||
# loop over triangles: | ||
# ia, ib, ic = indices of corner points of the triangle | ||
|
||
def alpha_shape(points,alpha): | ||
# circum_lst = [] | ||
tri = Delaunay(points) | ||
|
||
edges = set() | ||
edge_points = [] | ||
|
||
for ia, ib, ic in tri.vertices: | ||
pa = points[ia] | ||
pb = points[ib] | ||
pc = points[ic] | ||
|
||
# Lengths of sides of triangle | ||
a = math.sqrt((pa[0]-pb[0])**2 + (pa[1]-pb[1])**2) | ||
b = math.sqrt((pb[0]-pc[0])**2 + (pb[1]-pc[1])**2) | ||
c = math.sqrt((pc[0]-pa[0])**2 + (pc[1]-pa[1])**2) | ||
|
||
# Semiperimeter of triangle | ||
s = (a + b + c)/2.0 | ||
|
||
# Area of triangle by Heron's formula | ||
area = math.sqrt(s*(s-a)*(s-b)*(s-c)) | ||
|
||
circum_r = a*b*c/(4.0*area) | ||
|
||
# Here's the radius filter. | ||
# circum_lst.append(circum_r) | ||
# print('val = ',circum_r) | ||
# print('limit = ',1.0/alpha) | ||
# | ||
if circum_r < 1.0/alpha: | ||
add_edge(edges,edge_points, points, ia, ib) | ||
add_edge(edges,edge_points, points, ib, ic) | ||
add_edge(edges,edge_points, points, ic, ia) | ||
|
||
# print('ave = ',sum(circum_lst)/len(circum_lst)) | ||
|
||
m = MultiLineString(edge_points) | ||
triangles = list(polygonize(m)) | ||
|
||
# ## Show Result | ||
# # shoaw result of triangular | ||
# lines = LineCollection(edge_points,linewidths=(0.5, 1, 1.5, 2)) | ||
# plt.figure() | ||
# plt.title('Alpha=2.0 Delaunay triangulation') | ||
# plt.plot(points[:,0], points[:,1], 'o', hold=1, color='#f16824') | ||
# plt.gca().add_collection(lines) | ||
# | ||
# # show result of connected contour | ||
# plt.figure() | ||
# plt.title("Alpha=2.0 Hull") | ||
# plt.gca().add_patch(PolygonPatch(cascaded_union(triangles), alpha=0.5)) | ||
# plt.gca().autoscale(tight=False) | ||
# plt.plot(points[:,0], points[:,1], 'o', hold=1) | ||
# plt.show() | ||
|
||
return triangles, edge_points | ||
|
||
if __name__ == '__main__' : | ||
|
||
# pts of extending points calculated from HPE result | ||
points = np.array([[79, 441], [85, 370], [150, 447], [98, 360], [173, 427], [166, 285], [241, 352], \ | ||
[372, 320], [337, 413], [270, 282], [235, 375], [501, 445], [480, 377], [433, 466], [205, 238], \ | ||
[298, 276], [254, 234], [299, 145], [214, 216], [257, 125], [338, 157], [307, 252], [342, 81], \ | ||
[274, 98], [359, 149], [58, 68], [127, 52], [74, 137], [190, 91], [145, 180], [365, 163], [344, 260], \ | ||
[446, 194], [387, 154], [406, 253]]) | ||
|
||
|
||
alpha = 0.013 | ||
|
||
triangles, edge_points = alpha_shape(points, alpha) | ||
|
||
|
||
|
||
|
||
|
Binary file not shown.
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,36 @@ | ||
[param] | ||
|
||
# CPU mode or GPU mode | ||
use_gpu = 1 | ||
|
||
# GPU device number (doesn't matter for CPU mode) | ||
GPUdeviceNumber = 0 | ||
|
||
# Select model (default: 1) | ||
modelID = 1 | ||
|
||
# Look in matlab counterpart for explanation | ||
octave = 3 | ||
starting_range = 0.8 | ||
ending_range = 2 | ||
scale_search = 0.5, 1, 1.5, 2 | ||
thre1 = 0.1 | ||
thre2 = 0.05 | ||
thre3 = 0.5 | ||
min_num = 4 | ||
mid_num = 10 | ||
crop_ratio = 2.5 | ||
bbox_ratio = 0.25 | ||
|
||
[models] | ||
## don't edit this part | ||
|
||
[[1]] | ||
caffemodel = '../../model/_trained_COCO/pose_iter_440000.caffemodel' | ||
deployFile = '../../model/_trained_COCO/pose_deploy.prototxt' | ||
description = 'COCO Pose56 Two-level Linevec' | ||
boxsize = 368 | ||
padValue = 128 | ||
np = 12 | ||
stride = 8 | ||
part_str = [nose, neck, Rsho, Relb, Rwri, Lsho, Lelb, Lwri, Rhip, Rkne, Rank, Lhip, Lkne, Lank, Leye, Reye, Lear, Rear, pt19] |
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
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
109 changes: 60 additions & 49 deletions
109
demo_testing.ipynb → testing/python/demo_testing.ipynb
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.