Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
3
3dface
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
人工智能
3dface
Commits
fc0d53c5
Commit
fc0d53c5
authored
Apr 11, 2019
by
任婷婷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first commit
parents
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
251 additions
and
0 deletions
+251
-0
angle.py
angle.py
+136
-0
landmark68.obj
data/landmark68.obj
+69
-0
distance.py
distance.py
+46
-0
No files found.
angle.py
0 → 100644
View file @
fc0d53c5
import
argparse
import
pymeshio.common
import
pymeshio.obj.reader
import
math
import
numpy
as
np
def
get_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"This script calculate the angle between two lines"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
"--index"
,
"-i"
,
type
=
str
,
required
=
True
,
help
=
"indexes of 4 points in the 68 points"
)
parser
.
add_argument
(
"--plane"
,
"-p"
,
type
=
str
,
default
=
'all'
,
required
=
True
,
help
=
"coodinate plane to calculate"
)
args
=
parser
.
parse_args
()
return
args
def
get_k
(
pt_1
,
pt_2
,
plane
):
if
pt_1
and
pt_2
:
if
plane
==
'all'
:
delta_x
=
abs
(
pt_1
.
x
-
pt_2
.
x
)
delta_y
=
abs
(
pt_1
.
y
-
pt_2
.
y
)
delta_z
=
abs
(
pt_1
.
z
-
pt_2
.
z
)
k_sets
=
[]
if
delta_x
==
0
:
k_xy
=
None
k_xz
=
None
if
delta_y
==
0
:
k_yz
=
None
if
delta_y
==
0
and
delta_x
!=
0
:
k_xy
=
0
if
delta_z
==
0
and
delta_x
!=
0
:
k_xz
=
0
if
delta_z
==
0
and
delta_y
!=
0
:
k_yz
=
0
if
delta_x
!=
0
and
delta_y
!=
0
:
k_xy
=
delta_y
/
delta_x
k_sets
.
append
(
k_xy
)
if
delta_x
!=
0
and
delta_z
!=
0
:
k_xz
=
delta_z
/
delta_x
k_sets
.
append
(
k_xz
)
if
delta_y
!=
0
and
delta_z
!=
0
:
k_yz
=
delta_z
/
delta_y
k_sets
.
append
(
k_yz
)
return
k_sets
if
plane
==
'xy'
:
delta_x
=
abs
(
pt_1
.
x
-
pt_2
.
x
)
delta_y
=
abs
(
pt_1
.
y
-
pt_2
.
y
)
if
delta_x
==
0
:
k
=
None
if
delta_y
==
0
and
delta_x
!=
0
:
k
=
0
if
delta_x
!=
0
and
delta_y
!=
0
:
k
=
delta_y
/
delta_x
return
k
if
plane
==
'yz'
:
delta_z
=
abs
(
pt_1
.
z
-
pt_2
.
z
)
delta_y
=
abs
(
pt_1
.
y
-
pt_2
.
y
)
if
delta_y
==
0
:
k
=
None
if
delta_z
==
0
and
delta_y
!=
0
:
k
=
0
if
delta_z
!=
0
and
delta_y
!=
0
:
k
=
delta_z
/
delta_y
return
k
if
plane
==
'xz'
:
delta_z
=
abs
(
pt_1
.
z
-
pt_2
.
z
)
delta_x
=
abs
(
pt_1
.
x
-
pt_2
.
x
)
if
delta_x
==
0
:
k
=
None
if
delta_z
==
0
and
delta_x
!=
0
:
k
=
0
if
delta_z
!=
0
and
delta_x
!=
0
:
k
=
delta_z
/
delta_x
return
k
def
point2angle
(
pts
,
plane
):
if
len
(
pts
)
!=
4
:
print
(
"failed to get all the four points"
)
return
None
if
plane
==
'xy'
or
plane
==
'yz'
or
plane
==
'xz'
:
k1
=
get_k
(
pts
[
0
],
pts
[
1
],
plane
)
k2
=
get_k
(
pts
[
2
],
pts
[
3
],
plane
)
if
k1
!=
None
and
k2
!=
None
:
tan_theta
=
abs
((
k1
-
k2
)
/
(
1
+
k1
*
k2
))
return
math
.
atan
(
tan_theta
)
else
:
return
None
else
:
k1_sets
=
get_k
(
pts
[
0
],
pts
[
1
],
plane
)
k1_xy
=
k1_sets
[
0
]
k1_xz
=
k1_sets
[
1
]
k1_yz
=
k1_sets
[
2
]
k2_sets
=
get_k
(
pts
[
2
],
pts
[
3
],
plane
)
k2_xy
=
k2_sets
[
0
]
k2_xz
=
k2_sets
[
1
]
k2_yz
=
k2_sets
[
2
]
theta_set
=
[]
if
k1_xy
!=
None
and
k2_xy
!=
None
and
k1_yz
!=
None
and
k2_yz
!=
None
and
k1_xz
!=
None
and
k2_xz
!=
None
:
tan_xy
=
abs
((
k1_xy
-
k2_xy
)
/
(
1
+
k1_xy
*
k2_xy
))
theta_xy
=
math
.
atan
(
tan_xy
)
tan_xz
=
abs
((
k1_xz
-
k2_xz
)
/
(
1
+
k1_xz
*
k2_xz
))
theta_xz
=
math
.
atan
(
tan_xz
)
tan_yz
=
abs
((
k1_yz
-
k2_yz
)
/
(
1
+
k1_yz
*
k2_yz
))
theta_yz
=
math
.
atan
(
tan_yz
)
theta_set
=
(
theta_xy
,
theta_xz
,
theta_yz
)
if
__name__
==
'__main__'
:
args
=
get_args
()
index
=
args
.
index
index
=
np
.
fromstring
(
index
,
dtype
=
int
,
sep
=
' '
)
plane
=
args
.
plane
OBJ_FILE
=
pymeshio
.
common
.
unicode
(
"../data/landmark68.obj"
)
model
=
pymeshio
.
obj
.
reader
.
read_from_file
(
OBJ_FILE
)
#print(len(model.vertices))
a
=
model
.
vertices
[
int
(
index
[
0
])]
b
=
model
.
vertices
[
int
(
index
[
1
])]
c
=
model
.
vertices
[
int
(
index
[
2
])]
d
=
model
.
vertices
[
int
(
index
[
3
])]
pts
=
(
a
,
b
,
c
,
d
)
#print(pts)
if
plane
==
'all'
:
angle_xy
=
point2angle
(
pts
,
'xy'
)
angle_yz
=
point2angle
(
pts
,
'yz'
)
angle_xz
=
point2angle
(
pts
,
'xz'
)
print
(
"[xy:"
,
angle_xy
,
"yz:"
,
angle_yz
,
"xz:"
,
angle_xz
,
"]"
)
else
:
angle
=
point2angle
(
pts
,
plane
)
print
(
"["
,
plane
,
":"
,
angle
,
"]"
)
data/landmark68.obj
0 → 100644
View file @
fc0d53c5
v -71.4128 40.1037 -68.5556
v -73.1422 19.2577 -69.1489
v -69.7362 -4.43512 -69.5747
v -64.0715 -25.0565 -71.644
v -56.8499 -44.0982 -71.8577
v -46.6908 -59.2566 -69.0546
v -35.4775 -69.335 -61.1317
v -19.2109 -80.0892 -47.6142
v 0.293087 -83.5464 -42.2949
v 23.9287 -79.3118 -48.9904
v 40.4494 -67.2664 -61.5245
v 51.7757 -54.7359 -67.575
v 61.5938 -38.9401 -71.7735
v 67.8925 -21.7246 -73.8379
v 72.7551 0.251899 -71.9487
v 75.1647 20.4029 -72.5079
v 73.7648 43.1656 -73.2483
v -63.5908 59.5166 -47.6519
v -54.9058 61.1533 -36.1623
v -44.0015 63.5528 -28.2706
v -32.087 62.1494 -24.0544
v -18.7974 59.9151 -21.4864
v 21.0675 62.2491 -21.902
v 32.8474 63.1247 -25.4555
v 44.5632 65.1421 -29.7769
v 54.6224 63.0103 -36.7599
v 66.4815 60.0264 -54.0271
v -1.15 43.2641 -20.3671
v 0.391855 31.5646 -15.1465
v 1.28134 21.7281 -9.24581
v 0.110501 5.27325 -1.17903
v -16.7022 -10.6358 -28.2676
v -7.24151 -12.4312 -22.4489
v 1.70025 -16.6432 -19.226
v 9.18824 -14.3704 -23.7148
v 18.7206 -11.6234 -28.43
v -54.9388 39.9386 -48.8153
v -41.349 46.9808 -35.1742
v -30.2219 42.958 -36.8039
v -22.1346 40.5277 -38.0209
v -32.1814 36.0084 -37.1653
v -41.1476 38.7271 -39.415
v 24.1771 38.1399 -38.54
v 32.3302 43.7182 -37.8227
v 44.5245 48.3033 -37.6141
v 54.5332 41.1395 -48.6157
v 42.5154 38.1497 -39.6002
v 32.2883 37.3 -38.1331
v -30.516 -38.2019 -41.748
v -18.3656 -37.7414 -34.0299
v -9.48099 -29.4892 -22.4969
v 2.16256 -36.44 -23.5286
v 14.376 -31.0109 -24.1168
v 21.961 -37.2536 -33.9826
v 34.1794 -38.0254 -43.3902
v 22.2206 -42.5925 -34.5259
v 12.1582 -49.3289 -30.5295
v -0.129799 -50.3519 -28.6565
v -9.00018 -50.147 -30.0908
v -18.7463 -42.7386 -35.3676
v -25.8248 -37.8866 -40.2936
v -11.4294 -38.6966 -30.3688
v 1.58228 -39.3306 -27.2442
v 15.574 -38.9523 -31.3893
v 31.6655 -36.4044 -41.2562
v 16.0941 -39.5462 -31.2205
v 0.859996 -40.3376 -27.3094
v -11.0435 -43.0418 -29.6648
\ No newline at end of file
distance.py
0 → 100644
View file @
fc0d53c5
import
argparse
import
pymeshio.common
import
pymeshio.obj.reader
import
math
import
numpy
as
np
def
get_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
"This script calculate the angle between two lines"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
"--index"
,
"-i"
,
type
=
str
,
required
=
True
,
help
=
"indexes of 4 points in the 68 points"
)
parser
.
add_argument
(
"--plane"
,
"-p"
,
type
=
str
,
default
=
'3d'
,
required
=
True
,
help
=
"coodinate plane to calculate"
)
args
=
parser
.
parse_args
()
return
args
if
__name__
==
'__main__'
:
args
=
get_args
()
plane
=
args
.
plane
index
=
args
.
index
#print(index)
index
=
np
.
fromstring
(
index
,
dtype
=
int
,
sep
=
' '
)
#print(index[0])
OBJ_FILE
=
pymeshio
.
common
.
unicode
(
"../data/landmark68.obj"
)
model
=
pymeshio
.
obj
.
reader
.
read_from_file
(
OBJ_FILE
)
#plane=args.plane
a
=
model
.
vertices
[
int
(
index
[
0
])]
b
=
model
.
vertices
[
int
(
index
[
1
])]
if
plane
==
'xy'
:
#print(int(a.x))
vec_a
=
np
.
array
([
a
.
x
,
a
.
y
])
vec_b
=
np
.
array
([
b
.
x
,
b
.
y
])
#dist=np.sqrt(np.sum(np.square(vec_a-vec_b)))
#print(dist)
if
plane
==
'xz'
:
vec_a
=
np
.
array
([
a
.
x
,
a
.
z
])
vec_b
=
np
.
array
([
b
.
x
,
b
.
z
])
if
plane
==
'yz'
:
vec_a
=
np
.
array
([
a
.
y
,
a
.
z
])
vec_b
=
np
.
array
([
b
.
y
,
b
.
z
])
if
plane
==
'3d'
:
vec_a
=
np
.
array
([
float
(
a
.
x
),
float
(
a
.
y
),
float
(
a
.
z
)])
vec_b
=
np
.
array
([
float
(
b
.
x
),
float
(
b
.
y
),
float
(
b
.
z
)])
dist
=
np
.
sqrt
(
np
.
sum
(
np
.
square
(
vec_a
-
vec_b
)))
print
(
"["
,
plane
,
"_dist:"
,
dist
,
"]"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment