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
63e4af85
Commit
63e4af85
authored
Dec 28, 2013
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added the first T-API example - CamShift tracking
parent
4a6c2ce3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
269 additions
and
10 deletions
+269
-10
CMakeLists.txt
samples/CMakeLists.txt
+2
-3
CMakeLists.txt
samples/c/CMakeLists.txt
+1
-1
CMakeLists.txt
samples/cpp/CMakeLists.txt
+1
-1
CMakeLists.txt
samples/gpu/CMakeLists.txt
+1
-1
CMakeLists.txt
samples/ocl/CMakeLists.txt
+3
-4
CMakeLists.txt
samples/tapi/CMakeLists.txt
+52
-0
camshift.cpp
samples/tapi/camshift.cpp
+209
-0
No files found.
samples/CMakeLists.txt
View file @
63e4af85
...
...
@@ -14,6 +14,7 @@ add_subdirectory(c)
add_subdirectory
(
cpp
)
add_subdirectory
(
gpu
)
add_subdirectory
(
ocl
)
add_subdirectory
(
tapi
)
if
(
WIN32 AND HAVE_DIRECTX
)
add_subdirectory
(
directx
)
...
...
@@ -23,7 +24,6 @@ if(ANDROID AND BUILD_ANDROID_EXAMPLES)
add_subdirectory
(
android
)
endif
()
#
# END OF BUILD CASE 1: Build samples with library sources
#
...
...
@@ -73,4 +73,4 @@ endif()
#
# END OF BUILD CASE 2: Build samples with library binaries
#
endif
()
\ No newline at end of file
endif
()
samples/c/CMakeLists.txt
View file @
63e4af85
...
...
@@ -51,7 +51,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
install
(
FILES
${
C_SAMPLES
}
DESTINATION share/OpenCV/samples/c
...
...
samples/cpp/CMakeLists.txt
View file @
63e4af85
...
...
@@ -99,7 +99,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
install
(
FILES
${
C_SAMPLES
}
DESTINATION share/OpenCV/samples/cpp
...
...
samples/gpu/CMakeLists.txt
View file @
63e4af85
...
...
@@ -91,7 +91,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
include
(
"performance/CMakeLists.txt"
)
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
install
(
FILES
${
install_list
}
DESTINATION share/OpenCV/samples/
${
project
}
...
...
samples/ocl/CMakeLists.txt
View file @
63e4af85
SET
(
OPENCV_OCL_SAMPLES_REQUIRED_DEPS opencv_core opencv_
flann opencv_
imgproc opencv_highgui
SET
(
OPENCV_OCL_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib opencv_ocl
opencv_nonfree opencv_bioinspired
)
opencv_ocl opencv_nonfree opencv_bioinspired
)
ocv_check_dependencies
(
${
OPENCV_OCL_SAMPLES_REQUIRED_DEPS
}
)
...
...
@@ -51,7 +50,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
install
(
FILES
${
install_list
}
DESTINATION share/OpenCV/samples/
${
project
}
...
...
samples/tapi/CMakeLists.txt
0 → 100644
View file @
63e4af85
SET
(
OPENCV_TAPI_SAMPLES_REQUIRED_DEPS opencv_core opencv_imgproc opencv_video opencv_highgui
)
ocv_check_dependencies
(
${
OPENCV_TAPI_SAMPLES_REQUIRED_DEPS
}
)
if
(
BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND
)
set
(
project
"tapi"
)
string
(
TOUPPER
"
${
project
}
"
project_upper
)
project
(
"
${
project
}
_samples"
)
ocv_include_modules
(
${
OPENCV_TAPI_SAMPLES_REQUIRED_DEPS
}
)
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
MACRO
(
OPENCV_DEFINE_TAPI_EXAMPLE name srcs
)
set
(
the_target
"example_
${
project
}
_
${
name
}
"
)
add_executable
(
${
the_target
}
${
srcs
}
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_TAPI_SAMPLES_REQUIRED_DEPS
}
)
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"
${
project
}
-example-
${
name
}
"
PROJECT_LABEL
"(EXAMPLE_
${
project_upper
}
)
${
name
}
"
)
if
(
ENABLE_SOLUTION_FOLDERS
)
set_target_properties
(
${
the_target
}
PROPERTIES FOLDER
"samples//
${
project
}
"
)
endif
()
if
(
WIN32
)
if
(
MSVC AND NOT BUILD_SHARED_LIBS
)
set_target_properties
(
${
the_target
}
PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG"
)
endif
()
install
(
TARGETS
${
the_target
}
RUNTIME DESTINATION
"
${
OPENCV_SAMPLES_BIN_INSTALL_PATH
}
/
${
project
}
"
COMPONENT main
)
endif
()
ENDMACRO
()
file
(
GLOB all_samples RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
*.cpp
)
foreach
(
sample_filename
${
all_samples
}
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
file
(
GLOB sample_srcs RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
${
sample
}
.*
)
OPENCV_DEFINE_TAPI_EXAMPLE
(
${
sample
}
${
sample_srcs
}
)
endforeach
()
endif
()
if
(
INSTALL_C_EXAMPLES AND NOT WIN32
)
file
(
GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd
)
install
(
FILES
${
install_list
}
DESTINATION share/OpenCV/samples/
${
project
}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
)
endif
()
samples/tapi/camshift.cpp
0 → 100644
View file @
63e4af85
#include "opencv2/core/utility.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <cctype>
static
cv
::
Mat
image
;
static
bool
backprojMode
=
false
;
static
bool
selectObject
=
false
;
static
int
trackObject
=
0
;
static
bool
showHist
=
true
;
static
cv
::
Point
origin
;
static
cv
::
Rect
selection
;
static
int
vmin
=
10
,
vmax
=
256
,
smin
=
30
;
static
void
onMouse
(
int
event
,
int
x
,
int
y
,
int
,
void
*
)
{
if
(
selectObject
)
{
selection
.
x
=
std
::
min
(
x
,
origin
.
x
);
selection
.
y
=
std
::
min
(
y
,
origin
.
y
);
selection
.
width
=
std
::
abs
(
x
-
origin
.
x
);
selection
.
height
=
std
::
abs
(
y
-
origin
.
y
);
selection
&=
cv
::
Rect
(
0
,
0
,
image
.
cols
,
image
.
rows
);
}
switch
(
event
)
{
case
cv
:
:
EVENT_LBUTTONDOWN
:
origin
=
cv
::
Point
(
x
,
y
);
selection
=
cv
::
Rect
(
x
,
y
,
0
,
0
);
selectObject
=
true
;
break
;
case
cv
:
:
EVENT_LBUTTONUP
:
selectObject
=
false
;
if
(
selection
.
width
>
0
&&
selection
.
height
>
0
)
trackObject
=
-
1
;
break
;
default:
break
;
}
}
static
void
help
()
{
std
::
cout
<<
"
\n
This is a demo that shows mean-shift based tracking using Transparent API
\n
"
"You select a color objects such as your face and it tracks it.
\n
"
"This reads from video camera (0 by default, or the camera number the user enters
\n
"
"Usage:
\n
"
" ./camshiftdemo [camera number]
\n
"
;
std
::
cout
<<
"
\n\n
Hot keys:
\n
"
"
\t
ESC - quit the program
\n
"
"
\t
c - stop the tracking
\n
"
"
\t
b - switch to/from backprojection view
\n
"
"
\t
h - show/hide object histogram
\n
"
"
\t
p - pause video
\n
"
"To initialize tracking, select the object with mouse
\n
"
;
}
int
main
(
int
argc
,
const
char
**
argv
)
{
help
();
cv
::
VideoCapture
cap
;
cv
::
Rect
trackWindow
;
int
hsize
=
16
;
float
hranges
[
2
]
=
{
0
,
180
};
const
float
*
phranges
=
hranges
;
const
char
*
const
keys
=
{
"{@camera_number| 0 | camera number}"
};
cv
::
CommandLineParser
parser
(
argc
,
argv
,
keys
);
int
camNum
=
parser
.
get
<
int
>
(
0
);
cap
.
open
(
camNum
);
if
(
!
cap
.
isOpened
())
{
help
();
std
::
cout
<<
"***Could not initialize capturing...***
\n
"
;
std
::
cout
<<
"Current parameter's value:
\n
"
;
parser
.
printMessage
();
return
EXIT_FAILURE
;
}
cv
::
namedWindow
(
"Histogram"
,
cv
::
WINDOW_NORMAL
);
cv
::
namedWindow
(
"CamShift Demo"
,
cv
::
WINDOW_NORMAL
);
cv
::
setMouseCallback
(
"CamShift Demo"
,
onMouse
,
NULL
);
cv
::
createTrackbar
(
"Vmin"
,
"CamShift Demo"
,
&
vmin
,
256
,
NULL
);
cv
::
createTrackbar
(
"Vmax"
,
"CamShift Demo"
,
&
vmax
,
256
,
NULL
);
cv
::
createTrackbar
(
"Smin"
,
"CamShift Demo"
,
&
smin
,
256
,
NULL
);
cv
::
Mat
frame
,
hsv
,
hue
,
mask
,
hist
,
histimg
=
cv
::
Mat
::
zeros
(
200
,
320
,
CV_8UC3
),
backproj
;
bool
paused
=
false
;
for
(
;
;
)
{
if
(
!
paused
)
{
cap
>>
frame
;
if
(
frame
.
empty
())
break
;
}
frame
.
copyTo
(
image
);
if
(
!
paused
)
{
cv
::
cvtColor
(
image
,
hsv
,
cv
::
COLOR_BGR2HSV
);
if
(
trackObject
)
{
int
_vmin
=
vmin
,
_vmax
=
vmax
;
cv
::
inRange
(
hsv
,
cv
::
Scalar
(
0
,
smin
,
std
::
min
(
_vmin
,
_vmax
)),
cv
::
Scalar
(
180
,
256
,
std
::
max
(
_vmin
,
_vmax
)),
mask
);
int
ch
[
2
]
=
{
0
,
0
};
hue
.
create
(
hsv
.
size
(),
hsv
.
depth
());
cv
::
mixChannels
(
&
hsv
,
1
,
&
hue
,
1
,
ch
,
1
);
if
(
trackObject
<
0
)
{
cv
::
Mat
roi
(
hue
,
selection
),
maskroi
(
mask
,
selection
);
cv
::
calcHist
(
&
roi
,
1
,
0
,
maskroi
,
hist
,
1
,
&
hsize
,
&
phranges
);
cv
::
normalize
(
hist
,
hist
,
0
,
255
,
cv
::
NORM_MINMAX
);
trackWindow
=
selection
;
trackObject
=
1
;
histimg
=
cv
::
Scalar
::
all
(
0
);
int
binW
=
histimg
.
cols
/
hsize
;
cv
::
Mat
buf
(
1
,
hsize
,
CV_8UC3
);
for
(
int
i
=
0
;
i
<
hsize
;
i
++
)
buf
.
at
<
cv
::
Vec3b
>
(
i
)
=
cv
::
Vec3b
(
cv
::
saturate_cast
<
uchar
>
(
i
*
180.
/
hsize
),
255
,
255
);
cv
::
cvtColor
(
buf
,
buf
,
cv
::
COLOR_HSV2BGR
);
for
(
int
i
=
0
;
i
<
hsize
;
i
++
)
{
int
val
=
cv
::
saturate_cast
<
int
>
(
hist
.
at
<
float
>
(
i
)
*
histimg
.
rows
/
255
);
cv
::
rectangle
(
histimg
,
cv
::
Point
(
i
*
binW
,
histimg
.
rows
),
cv
::
Point
((
i
+
1
)
*
binW
,
histimg
.
rows
-
val
),
cv
::
Scalar
(
buf
.
at
<
cv
::
Vec3b
>
(
i
)),
-
1
,
8
);
}
}
cv
::
calcBackProject
(
&
hue
,
1
,
0
,
hist
,
backproj
,
&
phranges
);
backproj
&=
mask
;
cv
::
RotatedRect
trackBox
=
cv
::
CamShift
(
backproj
,
trackWindow
,
cv
::
TermCriteria
(
cv
::
TermCriteria
::
EPS
|
cv
::
TermCriteria
::
COUNT
,
10
,
1
));
if
(
trackWindow
.
area
()
<=
1
)
{
int
cols
=
backproj
.
cols
,
rows
=
backproj
.
rows
,
r
=
(
std
::
min
(
cols
,
rows
)
+
5
)
/
6
;
trackWindow
=
cv
::
Rect
(
trackWindow
.
x
-
r
,
trackWindow
.
y
-
r
,
trackWindow
.
x
+
r
,
trackWindow
.
y
+
r
)
&
cv
::
Rect
(
0
,
0
,
cols
,
rows
);
}
if
(
backprojMode
)
cv
::
cvtColor
(
backproj
,
image
,
cv
::
COLOR_GRAY2BGR
);
cv
::
ellipse
(
image
,
trackBox
,
cv
::
Scalar
(
0
,
0
,
255
),
3
,
cv
::
LINE_AA
);
}
}
else
if
(
trackObject
<
0
)
paused
=
false
;
if
(
selectObject
&&
selection
.
width
>
0
&&
selection
.
height
>
0
)
{
cv
::
Mat
roi
(
image
,
selection
);
cv
::
bitwise_not
(
roi
,
roi
);
}
cv
::
imshow
(
"CamShift Demo"
,
image
);
cv
::
imshow
(
"Histogram"
,
histimg
);
char
c
=
(
char
)
cv
::
waitKey
(
10
);
if
(
c
==
27
)
break
;
switch
(
c
)
{
case
'b'
:
backprojMode
=
!
backprojMode
;
break
;
case
'c'
:
trackObject
=
0
;
histimg
=
cv
::
Scalar
::
all
(
0
);
break
;
case
'h'
:
showHist
=
!
showHist
;
if
(
!
showHist
)
cv
::
destroyWindow
(
"Histogram"
);
else
cv
::
namedWindow
(
"Histogram"
,
cv
::
WINDOW_AUTOSIZE
);
break
;
case
'p'
:
paused
=
!
paused
;
break
;
default:
break
;
}
}
return
EXIT_SUCCESS
;
}
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