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
1996ae4a
Commit
1996ae4a
authored
Dec 31, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
parents
dec25e85
bb930665
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
83 additions
and
40 deletions
+83
-40
OpenCVUtils.cmake
cmake/OpenCVUtils.cmake
+1
-1
py_features_harris.markdown
..._feature2d/py_features_harris/py_features_harris.markdown
+21
-21
calibration.cpp
modules/calib3d/src/calibration.cpp
+14
-6
test_chesscorners_badarg.cpp
modules/calib3d/test/test_chesscorners_badarg.cpp
+1
-0
test_misc.cpp
modules/core/test/test_misc.cpp
+35
-2
tf_importer.cpp
modules/dnn/src/tensorflow/tf_importer.cpp
+1
-1
rtrees.cpp
modules/ml/src/rtrees.cpp
+2
-2
tf_text_graph_ssd.py
samples/dnn/tf_text_graph_ssd.py
+6
-2
opencl-opencv-interop.cpp
samples/opencl/opencl-opencv-interop.cpp
+2
-1
lk_track.py
samples/python/lk_track.py
+0
-1
video.py
samples/python/video.py
+0
-3
No files found.
cmake/OpenCVUtils.cmake
View file @
1996ae4a
...
...
@@ -401,7 +401,7 @@ macro(ocv_clear_vars)
endmacro
()
set
(
OCV_COMPILER_FAIL_REGEX
"argument
'.*' is not valid"
# GCC 9+
"argument
.* is not valid"
# GCC 9+ (including support of unicode quotes)
"command line option .* is valid for .* but not for C
\\
+
\\
+"
# GNU
"command line option .* is valid for .* but not for C"
# GNU
"unrecognized .*option"
# GNU
...
...
doc/py_tutorials/py_feature2d/py_features_harris/py_features_harris.markdown
View file @
1996ae4a
...
...
@@ -7,25 +7,25 @@ Goal
In this chapter,
-
We will understand the concepts behind Harris Corner Detection.
-
We will see the functions:
**cv.cornerHarris()**
,
**cv.cornerSubPix()**
-
We will see the f
ollowing f
unctions:
**cv.cornerHarris()**
,
**cv.cornerSubPix()**
Theory
------
In last chapter, we saw that corners are regions in the image with large variation in intensity in
In
the
last chapter, we saw that corners are regions in the image with large variation in intensity in
all the directions. One early attempt to find these corners was done by
**
Chris Harris & Mike
Stephens
** in their paper **
A Combined Corner and Edge Detector
**
in 1988, so now it is called
Harris Corner Detector. He took this simple idea to a mathematical form. It basically finds the
the
Harris Corner Detector. He took this simple idea to a mathematical form. It basically finds the
difference in intensity for a displacement of
\f
$(u,v)
\f
$ in all directions. This is expressed as below:
\f
[
E(u,v) = \sum_{x,y} \underbrace{w(x,y)}_\text{window function} \, [\underbrace{I(x+u,y+v)}_\text{shifted intensity}-\underbrace{I(x,y)}_\text{intensity}
]
^2
\f
]
Window function is either a rectangular window or g
aussian window which gives weights to pixels
The window function is either a rectangular window or a G
aussian window which gives weights to pixels
underneath.
We have to maximize this function
\f
$E(u,v)
\f
$ for corner detection. That means
,
we have to maximize the
second term. Applying Taylor Expansion to above equation and using some mathematical steps (please
refer any standard text books you like for full derivation), we get the final equation as:
We have to maximize this function
\f
$E(u,v)
\f
$ for corner detection. That means we have to maximize the
second term. Applying Taylor Expansion to
the
above equation and using some mathematical steps (please
refer
to
any standard text books you like for full derivation), we get the final equation as:
\f
[
E(u,v) \approx \begin{bmatrix} u & v \end{bmatrix} M \begin{bmatrix} u \\ v \end{bmatrix}\f
]
...
...
@@ -34,20 +34,20 @@ where
\f
[
M =
\s
um_{x,y} w(x,y)
\b
egin{bmatrix}I_x I_x & I_x I_y
\\
I_x I_y & I_y I_y
\e
nd{bmatrix}
\f
]
Here,
\f
$I_x
\f
$ and
\f
$I_y
\f
$ are image derivatives in x and y directions respectively. (
C
an be easily found
out
using
**cv.Sobel()**
).
Here,
\f
$I_x
\f
$ and
\f
$I_y
\f
$ are image derivatives in x and y directions respectively. (
These c
an be easily found
using
**cv.Sobel()**
).
Then comes the main part. After this, they created a score, basically an equation, which
will
determine if a window can contain a corner or not.
Then comes the main part. After this, they created a score, basically an equation, which
determine
s
if a window can contain a corner or not.
\f
[
R = det(M) - k(trace(M))^2\f
]
where
-
\f
$det(M) =
\l
ambda_1
\l
ambda_2
\f
$
-
\f
$trace(M) =
\l
ambda_1 +
\l
ambda_2
\f
$
-
\f
$
\l
ambda_1
\f
$ and
\f
$
\l
ambda_2
\f
$ are the eigen
values of M
-
\f
$
\l
ambda_1
\f
$ and
\f
$
\l
ambda_2
\f
$ are the eigenvalues of M
So the
values of these eigen values decide whether a region is corner, edge
or flat.
So the
magnitudes of these eigenvalues decide whether a region is a corner, an edge,
or flat.
-
When
\f
$|R|
\f
$ is small, which happens when
\f
$
\l
ambda_1
\f
$ and
\f
$
\l
ambda_2
\f
$ are small, the region is
flat.
...
...
@@ -60,16 +60,16 @@ It can be represented in a nice picture as follows:
![
image
](
images/harris_region.jpg
)
So the result of Harris Corner Detection is a grayscale image with these scores. Thresholding for a
suitable
give
you the corners in the image. We will do it with a simple image.
suitable
score gives
you the corners in the image. We will do it with a simple image.
Harris Corner Detector in OpenCV
--------------------------------
OpenCV has the function
**cv.cornerHarris()**
for this purpose. Its arguments are
:
OpenCV has the function
**cv.cornerHarris()**
for this purpose. Its arguments are:
-
**img**
- Input image
, i
t should be grayscale and float32 type.
-
**img**
- Input image
. I
t should be grayscale and float32 type.
-
**blockSize**
- It is the size of neighbourhood considered for corner detection
-
**ksize**
- Aperture parameter of Sobel derivative used.
-
**ksize**
- Aperture parameter of
the
Sobel derivative used.
-
**k**
- Harris detector free parameter in the equation.
See the example below:
...
...
@@ -103,12 +103,12 @@ Corner with SubPixel Accuracy
Sometimes, you may need to find the corners with maximum accuracy. OpenCV comes with a function
**cv.cornerSubPix()**
which further refines the corners detected with sub-pixel accuracy. Below is
an example. As usual, we need to find the
h
arris corners first. Then we pass the centroids of these
an example. As usual, we need to find the
H
arris corners first. Then we pass the centroids of these
corners (There may be a bunch of pixels at a corner, we take their centroid) to refine them. Harris
corners are marked in red pixels and refined corners are marked in green pixels. For this function,
we have to define the criteria when to stop the iteration. We stop it after a specified number of
iteration or a certain accuracy is achieved, whichever occurs first. We also need to define the size
of
neighbourhood it would search
for corners.
iteration
s
or a certain accuracy is achieved, whichever occurs first. We also need to define the size
of
the neighbourhood it searches
for corners.
@code{.py}
import numpy as np
import cv2 as cv
...
...
@@ -139,7 +139,7 @@ img[res[:,3],res[:,2]] = [0,255,0]
cv.imwrite('subpixel5.png',img)
@endcode
Below is the result, where some important locations are shown in zoomed window to visualize:
Below is the result, where some important locations are shown in
the
zoomed window to visualize:
![
image
](
images/subpixel3.png
)
...
...
modules/calib3d/src/calibration.cpp
View file @
1996ae4a
...
...
@@ -250,8 +250,6 @@ CV_IMPL void cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
CV_IMPL
int
cvRodrigues2
(
const
CvMat
*
src
,
CvMat
*
dst
,
CvMat
*
jacobian
)
{
int
depth
,
elem_size
;
int
i
,
k
;
double
J
[
27
]
=
{
0
};
CvMat
matJ
=
cvMat
(
3
,
9
,
CV_64F
,
J
);
...
...
@@ -262,8 +260,8 @@ CV_IMPL int cvRodrigues2( const CvMat* src, CvMat* dst, CvMat* jacobian )
CV_Error
(
!
dst
?
CV_StsNullPtr
:
CV_StsBadArg
,
"The first output argument is not a valid matrix"
);
depth
=
CV_MAT_DEPTH
(
src
->
type
);
elem_size
=
CV_ELEM_SIZE
(
depth
);
int
depth
=
CV_MAT_DEPTH
(
src
->
type
);
int
elem_size
=
CV_ELEM_SIZE
(
depth
);
if
(
depth
!=
CV_32F
&&
depth
!=
CV_64F
)
CV_Error
(
CV_StsUnsupportedFormat
,
"The matrices must have 32f or 64f data type"
);
...
...
@@ -349,12 +347,12 @@ CV_IMPL int cvRodrigues2( const CvMat* src, CvMat* dst, CvMat* jacobian )
double
d_r_x_
[]
=
{
0
,
0
,
0
,
0
,
0
,
-
1
,
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
-
1
,
0
,
0
,
0
,
-
1
,
0
,
1
,
0
,
0
,
0
,
0
,
0
};
for
(
i
=
0
;
i
<
3
;
i
++
)
for
(
i
nt
i
=
0
;
i
<
3
;
i
++
)
{
double
ri
=
i
==
0
?
r
.
x
:
i
==
1
?
r
.
y
:
r
.
z
;
double
a0
=
-
s
*
ri
,
a1
=
(
s
-
2
*
c1
*
itheta
)
*
ri
,
a2
=
c1
*
itheta
;
double
a3
=
(
c
-
s
*
itheta
)
*
ri
,
a4
=
s
*
itheta
;
for
(
k
=
0
;
k
<
9
;
k
++
)
for
(
int
k
=
0
;
k
<
9
;
k
++
)
J
[
i
*
9
+
k
]
=
a0
*
I
[
k
]
+
a1
*
rrt
.
val
[
k
]
+
a2
*
drrt
[
i
*
9
+
k
]
+
a3
*
r_x
.
val
[
k
]
+
a4
*
d_r_x_
[
i
*
9
+
k
];
}
...
...
@@ -490,6 +488,10 @@ CV_IMPL int cvRodrigues2( const CvMat* src, CvMat* dst, CvMat* jacobian )
dst
->
data
.
db
[
step
*
2
]
=
r
.
z
;
}
}
else
{
CV_Error
(
CV_StsBadSize
,
"Input matrix must be 1x3 or 3x1 for a rotation vector, or 3x3 for a rotation matrix"
);
}
if
(
jacobian
)
{
...
...
@@ -3465,6 +3467,12 @@ void cv::Rodrigues(InputArray _src, OutputArray _dst, OutputArray _jacobian)
CV_INSTRUMENT_REGION
();
Mat
src
=
_src
.
getMat
();
const
Size
srcSz
=
src
.
size
();
CV_Check
(
srcSz
,
srcSz
==
Size
(
3
,
1
)
||
srcSz
==
Size
(
1
,
3
)
||
(
srcSz
==
Size
(
1
,
1
)
&&
src
.
channels
()
==
3
)
||
srcSz
==
Size
(
3
,
3
),
"Input matrix must be 1x3 or 3x1 for a rotation vector, or 3x3 for a rotation matrix"
);
bool
v2m
=
src
.
cols
==
1
||
src
.
rows
==
1
;
_dst
.
create
(
3
,
v2m
?
3
:
1
,
src
.
depth
());
Mat
dst
=
_dst
.
getMat
();
...
...
modules/calib3d/test/test_chesscorners_badarg.cpp
View file @
1996ae4a
...
...
@@ -95,6 +95,7 @@ void CV_ChessboardDetectorBadArgTest::run( int /*start_from */)
initArgs
();
pattern_size
=
Size
(
2
,
2
);
errors
+=
run_test_case
(
Error
::
StsOutOfRange
,
"Invalid pattern size"
);
pattern_size
=
cbg
.
cornersSize
();
cb
.
convertTo
(
img
,
CV_32F
);
...
...
modules/core/test/test_misc.cpp
View file @
1996ae4a
...
...
@@ -671,7 +671,8 @@ TEST(Core_Check, testMatType_fail_2)
EXPECT_STREQ
(
e
.
err
.
c_str
(),
"> Unsupported src:
\n
"
"> 'src_type == CV_32FC1 || src_type == CV_32FC3'
\n
"
"> where
\n
> 'src_type' is 0 (CV_8UC1)
\n
"
"> where
\n
"
"> 'src_type' is 0 (CV_8UC1)
\n
"
);
}
catch
(
const
std
::
exception
&
e
)
...
...
@@ -737,7 +738,39 @@ TEST(Core_Check, testMatDepth_fail_2)
EXPECT_STREQ
(
e
.
err
.
c_str
(),
"> Unsupported src:
\n
"
"> 'src_depth == CV_32F || src_depth == CV_64F'
\n
"
"> where
\n
> 'src_depth' is 0 (CV_8U)
\n
"
"> where
\n
"
"> 'src_depth' is 0 (CV_8U)
\n
"
);
}
catch
(
const
std
::
exception
&
e
)
{
FAIL
()
<<
"Unexpected C++ exception: "
<<
e
.
what
();
}
catch
(...)
{
FAIL
()
<<
"Unexpected unknown exception"
;
}
}
void
test_check_Size_1
(
const
Size
&
srcSz
)
{
CV_Check
(
srcSz
,
srcSz
==
Size
(
4
,
3
),
"Unsupported src size"
);
}
TEST
(
Core_Check
,
testSize_1
)
{
try
{
test_check_Size_1
(
Size
(
2
,
1
));
FAIL
()
<<
"Unreachable code called"
;
}
catch
(
const
cv
::
Exception
&
e
)
{
EXPECT_STREQ
(
e
.
err
.
c_str
(),
"> Unsupported src size:
\n
"
"> 'srcSz == Size(4, 3)'
\n
"
"> where
\n
"
"> 'srcSz' is [2 x 1]
\n
"
);
}
catch
(
const
std
::
exception
&
e
)
...
...
modules/dnn/src/tensorflow/tf_importer.cpp
View file @
1996ae4a
...
...
@@ -996,7 +996,7 @@ void TFImporter::populateNet(Net dstNet)
if
(
getDataLayout
(
name
,
data_layouts
)
==
DATA_LAYOUT_UNKNOWN
)
data_layouts
[
name
]
=
DATA_LAYOUT_NHWC
;
}
else
if
(
type
==
"BiasAdd"
||
type
==
"Add"
||
type
==
"Sub"
||
type
==
"AddN"
)
else
if
(
type
==
"BiasAdd"
||
type
==
"Add"
||
type
==
"
AddV2"
||
type
==
"
Sub"
||
type
==
"AddN"
)
{
bool
haveConst
=
false
;
for
(
int
ii
=
0
;
!
haveConst
&&
ii
<
layer
.
input_size
();
++
ii
)
...
...
modules/ml/src/rtrees.cpp
View file @
1996ae4a
...
...
@@ -90,12 +90,12 @@ public:
CV_TRACE_FUNCTION
();
DTreesImpl
::
clear
();
oobError
=
0.
;
rng
=
RNG
((
uint64
)
-
1
);
}
const
vector
<
int
>&
getActiveVars
()
CV_OVERRIDE
{
CV_TRACE_FUNCTION
();
RNG
&
rng
=
theRNG
();
int
i
,
nvars
=
(
int
)
allVars
.
size
(),
m
=
(
int
)
activeVars
.
size
();
for
(
i
=
0
;
i
<
nvars
;
i
++
)
{
...
...
@@ -134,6 +134,7 @@ public:
bool
train
(
const
Ptr
<
TrainData
>&
trainData
,
int
flags
)
CV_OVERRIDE
{
CV_TRACE_FUNCTION
();
RNG
&
rng
=
theRNG
();
CV_Assert
(
!
trainData
.
empty
());
startTraining
(
trainData
,
flags
);
int
treeidx
,
ntrees
=
(
rparams
.
termCrit
.
type
&
TermCriteria
::
COUNT
)
!=
0
?
...
...
@@ -424,7 +425,6 @@ public:
double
oobError
;
vector
<
float
>
varImportance
;
vector
<
int
>
allVars
,
activeVars
;
RNG
rng
;
};
...
...
samples/dnn/tf_text_graph_ssd.py
View file @
1996ae4a
...
...
@@ -62,7 +62,7 @@ class MultiscaleAnchorGenerator:
def
createSSDGraph
(
modelPath
,
configPath
,
outputPath
):
# Nodes that should be kept.
keepOps
=
[
'Conv2D'
,
'BiasAdd'
,
'Add'
,
'Relu'
,
'Relu6'
,
'Placeholder'
,
'FusedBatchNorm'
,
keepOps
=
[
'Conv2D'
,
'BiasAdd'
,
'Add'
,
'
AddV2'
,
'
Relu'
,
'Relu6'
,
'Placeholder'
,
'FusedBatchNorm'
,
'DepthwiseConv2dNative'
,
'ConcatV2'
,
'Mul'
,
'MaxPool'
,
'AvgPool'
,
'Identity'
,
'Sub'
,
'ResizeNearestNeighbor'
,
'Pad'
,
'FusedBatchNormV3'
]
...
...
@@ -151,6 +151,9 @@ def createSSDGraph(modelPath, configPath, outputPath):
subgraphBatchNorm
=
[
'Add'
,
[
'Mul'
,
'input'
,
[
'Mul'
,
[
'Rsqrt'
,
[
'Add'
,
'moving_variance'
,
'add_y'
]],
'gamma'
]],
[
'Sub'
,
'beta'
,
[
'Mul'
,
'moving_mean'
,
'Mul_0'
]]]
subgraphBatchNormV2
=
[
'AddV2'
,
[
'Mul'
,
'input'
,
[
'Mul'
,
[
'Rsqrt'
,
[
'AddV2'
,
'moving_variance'
,
'add_y'
]],
'gamma'
]],
[
'Sub'
,
'beta'
,
[
'Mul'
,
'moving_mean'
,
'Mul_0'
]]]
# Detect unfused nearest neighbor resize.
subgraphResizeNN
=
[
'Reshape'
,
[
'Mul'
,
[
'Reshape'
,
'input'
,
[
'Pack'
,
'shape_1'
,
'shape_2'
,
'shape_3'
,
'shape_4'
,
'shape_5'
]],
...
...
@@ -177,7 +180,8 @@ def createSSDGraph(modelPath, configPath, outputPath):
for
node
in
graph_def
.
node
:
inputs
=
{}
fusedNodes
=
[]
if
checkSubgraph
(
node
,
subgraphBatchNorm
,
inputs
,
fusedNodes
):
if
checkSubgraph
(
node
,
subgraphBatchNorm
,
inputs
,
fusedNodes
)
or
\
checkSubgraph
(
node
,
subgraphBatchNormV2
,
inputs
,
fusedNodes
):
name
=
node
.
name
node
.
Clear
()
node
.
name
=
name
...
...
samples/opencl/opencl-opencv-interop.cpp
View file @
1996ae4a
...
...
@@ -17,6 +17,7 @@
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#define CL_USE_DEPRECATED_OPENCL_2_0_APIS // eliminate build warning
#define CL_TARGET_OPENCL_VERSION 200 // 2.0
#ifdef __APPLE__
#define CL_SILENCE_DEPRECATION
...
...
@@ -677,7 +678,7 @@ int App::initVideoSource()
throw
std
::
runtime_error
(
std
::
string
(
"specify video source"
));
}
catch
(
const
std
::
exception
e
)
catch
(
const
std
::
exception
&
e
)
{
cerr
<<
"ERROR: "
<<
e
.
what
()
<<
std
::
endl
;
return
-
1
;
...
...
samples/python/lk_track.py
View file @
1996ae4a
...
...
@@ -26,7 +26,6 @@ import cv2 as cv
import
video
from
common
import
anorm2
,
draw_str
from
time
import
clock
lk_params
=
dict
(
winSize
=
(
15
,
15
),
maxLevel
=
2
,
...
...
samples/python/video.py
View file @
1996ae4a
...
...
@@ -39,9 +39,6 @@ import re
from
numpy
import
pi
,
sin
,
cos
# built-in modules
from
time
import
clock
# local modules
from
tst_scene_render
import
TestSceneRender
import
common
...
...
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