Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
7a713a49
Commit
7a713a49
authored
Jan 11, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
collect Caltech positives for 32x64 octave:
- resized - cropped - flipped around the x axis
parent
56edff90
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
26 deletions
+74
-26
scale_caltech.py
apps/sft/misk/scale_caltech.py
+70
-22
scale_inria.py
apps/sft/misk/scale_inria.py
+4
-4
No files found.
apps/sft/misk/scale_caltech.py
View file @
7a713a49
...
...
@@ -6,11 +6,30 @@ from optparse import OptionParser
import
re
import
numpy
as
np
def
resize
(
image
,
d_w
,
d_h
):
if
(
d_h
<
image
.
shape
[
0
])
or
(
d_w
<
image
.
shape
[
1
]):
ratio
=
min
(
d_h
/
float
(
image
.
shape
[
0
]),
d_w
/
float
(
image
.
shape
[
1
]))
kernel_size
=
int
(
5
/
(
2
*
ratio
))
sigma
=
0.5
/
ratio
image_to_resize
=
cv2
.
filter2D
(
image
,
cv2
.
CV_8UC3
,
cv2
.
getGaussianKernel
(
kernel_size
,
sigma
))
interpolation_type
=
cv2
.
INTER_AREA
else
:
image_to_resize
=
image
interpolation_type
=
cv2
.
INTER_CUBIC
return
cv2
.
resize
(
image_to_resize
,(
d_w
,
d_h
),
None
,
0
,
0
,
interpolation_type
)
def
showPeople
(
f
,
path
,
opath
):
newobj
=
re
.
compile
(
"^lbl=
\'
(
\
w+)
\'
\
s+str=(
\
d+)
\
s+end=(
\
d+)
\
s+hide=0$"
)
pos
=
re
.
compile
(
"^pos
\
s=(
\
[[((
\
d+
\
.+
\
d*)|
\
s+|
\
;)]*
\
])$"
)
occl
=
re
.
compile
(
"^occl
\
s*=(
\
[[0-1|
\
s]*
\
])$"
)
octave
=
0.5
whole_mod_w
=
int
(
64
*
octave
)
+
2
*
int
(
20
*
octave
)
whole_mod_h
=
int
(
128
*
octave
)
+
2
*
int
(
20
*
octave
)
goNext
=
0
start
=
0
end
=
0
...
...
@@ -23,7 +42,6 @@ def showPeople(f, path, opath):
for
l
in
f
:
m
=
newobj
.
match
(
l
)
if
m
is
not
None
:
print
m
.
group
(
1
)
if
m
.
group
(
1
)
==
"person"
:
goNext
=
1
start
=
int
(
m
.
group
(
2
))
...
...
@@ -45,40 +63,70 @@ def showPeople(f, path, opath):
occls
=
eval
(
re
.
sub
(
r"\s+(?!\])"
,
","
,
m
.
group
(
1
)))
if
len
(
boxes
)
>
0
and
len
(
boxes
)
==
len
(
occls
):
print
len
(
boxes
)
for
idx
,
box
in
enumerate
(
boxes
):
color
=
(
8
,
107
,
255
)
if
occls
[
idx
]
==
1
:
continue
# color = (255, 107, 8)
x
=
box
[
0
]
y
=
box
[
1
]
w
=
box
[
2
]
h
=
box
[
3
]
id
=
int
(
start
)
-
1
+
idx
file
=
os
.
path
.
join
(
path
,
"I0
%04
d.jpg"
%
id
)
print
file
if
(
start
+
id
)
>=
end
or
w
<
10
or
h
<
64
:
continue
mat
=
cv2
.
imread
(
file
)
mat_h
,
mat_w
,
_
=
mat
.
shape
scale
=
h
/
float
(
96
)
rel_scale
=
scale
/
octave
d_w
=
whole_mod_w
*
rel_scale
d_h
=
whole_mod_h
*
rel_scale
tb
=
(
d_h
-
h
)
/
2.0
lr
=
(
d_w
-
w
)
/
2.0
x
=
int
(
round
(
x
-
lr
))
y
=
int
(
round
(
y
-
tb
))
w
=
int
(
round
(
w
+
lr
*
2.0
))
h
=
int
(
round
(
h
+
tb
*
2.0
))
inner
=
[
max
(
5
,
x
),
max
(
5
,
y
),
min
(
mat_w
-
5
,
x
+
w
),
min
(
mat_h
-
5
,
y
+
h
)
]
cropped
=
mat
[
inner
[
1
]:
inner
[
3
],
inner
[
0
]:
inner
[
2
],
:]
top
=
int
(
max
(
0
,
0
-
y
))
bottom
=
int
(
max
(
0
,
y
+
h
-
mat_h
))
left
=
int
(
max
(
0
,
0
-
x
))
right
=
int
(
max
(
0
,
x
+
w
-
mat_w
))
if
top
<
-
d_h
/
4.0
or
bottom
>
d_h
/
4.0
or
left
<
-
d_w
/
4.0
or
right
>
d_w
/
4.0
:
continue
if
(
start
+
id
)
<
end
and
w
>
5
and
h
>
47
:
img
=
cv2
.
imread
(
file
)
cropped
=
cv2
.
copyMakeBorder
(
cropped
,
top
,
bottom
,
left
,
right
,
cv2
.
BORDER_REPLICATE
)
resized
=
resize
(
cropped
,
whole_mod_w
,
whole_mod_h
)
flipped
=
cv2
.
flip
(
resized
,
1
)
fname
=
re
.
sub
(
r"^.*\/(set[0-1]\d)\/(V0\d\d)\.(seq)/(I\d+).jpg$"
,
"
\\
1_
\\
2_
\\
4"
,
file
)
#os.path.basename(file)
fname
=
os
.
path
.
join
(
opath
,
fname
+
"_
%04
d."
%
person_id
+
"png"
)
try
:
print
"->"
,
fname
submat
=
img
[
int
(
y
):
int
(
y
+
h
),
int
(
x
):
int
(
x
+
w
),:]
cv2
.
imwrite
(
fname
,
submat
)
except
:
print
"something wrong... go next."
pass
cv2
.
rectangle
(
img
,
(
int
(
x
),
int
(
y
)),
(
int
(
x
+
w
),
int
(
y
+
h
)),
color
,
1
)
cv2
.
imshow
(
"person"
,
img
)
cv2
.
imshow
(
"resized"
,
resized
)
c
=
cv2
.
waitKey
(
1
0
)
if
c
==
27
:
exit
(
0
)
c
=
cv2
.
waitKey
(
2
0
)
if
c
==
27
:
exit
(
0
)
fname
=
re
.
sub
(
r"^.*\/(set[0-1]\d)\/(V0\d\d)\.(seq)/(I\d+).jpg$"
,
"
\\
1_
\\
2_
\\
4"
,
file
)
fname
=
os
.
path
.
join
(
opath
,
fname
+
"_
%04
d."
%
person_id
+
"png"
)
fname_fl
=
os
.
path
.
join
(
opath
,
fname
+
"_mirror_
%04
d."
%
person_id
+
"png"
)
try
:
cv2
.
imwrite
(
fname
,
resized
)
cv2
.
imwrite
(
fname_fl
,
flipped
)
except
:
print
"something wrong... go next."
pass
if
__name__
==
"__main__"
:
parser
=
OptionParser
()
...
...
@@ -93,10 +141,10 @@ if __name__ == "__main__":
if
not
options
.
input
:
parser
.
error
(
"Caltech dataset folder is required."
)
opath
=
os
.
path
.
join
(
options
.
output
,
datetime
.
now
()
.
strftime
(
"raw_ge
48-
"
+
"-
%
Y-
%
m-
%
d-
%
H-
%
M-
%
S"
))
opath
=
os
.
path
.
join
(
options
.
output
,
datetime
.
now
()
.
strftime
(
"raw_ge
64_cr_mirr_ts
"
+
"-
%
Y-
%
m-
%
d-
%
H-
%
M-
%
S"
))
os
.
mkdir
(
opath
)
gl
=
glob
.
iglob
(
os
.
path
.
join
(
options
.
input
,
"set[0-1][0-
9
]/V0[0-9][0-9].txt"
))
gl
=
glob
.
iglob
(
os
.
path
.
join
(
options
.
input
,
"set[0-1][0-
5
]/V0[0-9][0-9].txt"
))
for
each
in
gl
:
path
,
ext
=
os
.
path
.
splitext
(
each
)
path
=
path
+
".seq"
...
...
apps/sft/misk/scale_inria.py
View file @
7a713a49
...
...
@@ -105,10 +105,10 @@ if __name__ == "__main__":
cropped
=
mat
[
inner
[
1
]:
inner
[
3
],
inner
[
0
]:
inner
[
2
],
:]
top
=
int
(
max
(
0
,
0
-
box
[
1
]))
bottom
=
int
(
max
(
0
,
box
[
3
]
-
mat_h
))
left
=
int
(
max
(
0
,
0
-
box
[
0
]))
right
=
int
(
max
(
0
,
box
[
2
]
-
mat_w
))
top
=
int
(
max
(
0
,
0
-
box
[
1
]))
bottom
=
int
(
max
(
0
,
box
[
3
]
-
mat_h
))
left
=
int
(
max
(
0
,
0
-
box
[
0
]))
right
=
int
(
max
(
0
,
box
[
2
]
-
mat_w
))
cropped
=
cv2
.
copyMakeBorder
(
cropped
,
top
,
bottom
,
left
,
right
,
cv2
.
BORDER_REPLICATE
)
resized
=
resize
(
cropped
,
whole_mod_w
,
whole_mod_h
)
...
...
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