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
470f6faf
Commit
470f6faf
authored
Mar 31, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed conversions from YV12 and IYUV on non-continuous input. Added accuracy and performance tests.
parent
a22641aa
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
48 deletions
+44
-48
perf_cvt_color.cpp
modules/imgproc/perf/perf_cvt_color.cpp
+0
-0
color.cpp
modules/imgproc/src/color.cpp
+44
-48
test_cvtyuv.cpp
modules/imgproc/test/test_cvtyuv.cpp
+0
-0
No files found.
modules/imgproc/perf/perf_cvt_color.cpp
View file @
470f6faf
This diff is collapsed.
Click to expand it.
modules/imgproc/src/color.cpp
View file @
470f6faf
...
...
@@ -2829,22 +2829,18 @@ struct YUV420p2RGB888Invoker
Mat
*
dst
;
const
uchar
*
my1
,
*
mu
,
*
mv
;
int
width
,
stride
;
int
ustepIdx
,
vstepIdx
;
YUV420p2RGB888Invoker
(
Mat
*
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
)
:
dst
(
_dst
),
my1
(
_y1
),
mu
(
_u
),
mv
(
_v
),
width
(
_dst
->
cols
),
stride
(
_stride
)
{}
YUV420p2RGB888Invoker
(
Mat
*
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
,
int
_ustepIdx
,
int
_vstepIdx
)
:
dst
(
_dst
),
my1
(
_y1
),
mu
(
_u
),
mv
(
_v
),
width
(
_dst
->
cols
),
stride
(
_stride
)
,
ustepIdx
(
_ustepIdx
),
vstepIdx
(
_vstepIdx
)
{}
void
operator
()(
const
BlockedRange
&
range
)
const
{
const
int
rangeBegin
=
range
.
begin
()
*
2
;
const
int
rangeEnd
=
range
.
end
()
*
2
;
//R = 1.164(Y - 16) + 1.596(V - 128)
//G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
//B = 1.164(Y - 16) + 2.018(U - 128)
//R = (1220542(Y - 16) + 1673527(V - 128) + (1 << 19)) >> 20
//G = (1220542(Y - 16) - 852492(V - 128) - 409993(U - 128) + (1 << 19)) >> 20
//B = (1220542(Y - 16) + 2116026(U - 128) + (1 << 19)) >> 20
size_t
uvsteps
[
2
]
=
{
width
/
2
,
stride
-
width
/
2
};
int
usIdx
=
ustepIdx
,
vsIdx
=
vstepIdx
;
const
int
cY
=
1220542
;
const
int
cUB
=
2116026
;
...
...
@@ -2854,10 +2850,16 @@ struct YUV420p2RGB888Invoker
const
int
YUV420_SHIFT
=
20
;
const
uchar
*
y1
=
my1
+
rangeBegin
*
stride
;
const
uchar
*
u1
=
mu
+
(
range
.
begin
()
/
2
)
*
stride
+
(
range
.
begin
()
%
2
)
*
width
/
2
;
const
uchar
*
v1
=
mv
+
(
range
.
begin
()
/
2
)
*
stride
+
(
range
.
begin
()
%
2
)
*
width
/
2
;
const
uchar
*
u1
=
mu
+
(
range
.
begin
()
/
2
)
*
stride
;
const
uchar
*
v1
=
mv
+
(
range
.
begin
()
/
2
)
*
stride
;
if
(
range
.
begin
()
%
2
==
1
)
{
u1
+=
uvsteps
[(
usIdx
++
)
&
1
];
v1
+=
uvsteps
[(
vsIdx
++
)
&
1
];
}
for
(
int
j
=
rangeBegin
;
j
<
rangeEnd
;
j
+=
2
,
y1
+=
stride
*
2
,
u1
+=
width
/
2
,
v1
+=
width
/
2
)
for
(
int
j
=
rangeBegin
;
j
<
rangeEnd
;
j
+=
2
,
y1
+=
stride
*
2
,
u1
+=
uvsteps
[(
usIdx
++
)
&
1
],
v1
+=
uvsteps
[(
vsIdx
++
)
&
1
]
)
{
uchar
*
row1
=
dst
->
ptr
<
uchar
>
(
j
);
uchar
*
row2
=
dst
->
ptr
<
uchar
>
(
j
+
1
);
...
...
@@ -2892,12 +2894,6 @@ struct YUV420p2RGB888Invoker
row2
[
4
]
=
saturate_cast
<
uchar
>
((
y11
+
guv
)
>>
YUV420_SHIFT
);
row2
[
3
+
bIdx
]
=
saturate_cast
<
uchar
>
((
y11
+
buv
)
>>
YUV420_SHIFT
);
}
if
(
j
%
4
==
2
)
{
u1
+=
stride
-
width
;
v1
+=
stride
-
width
;
}
}
}
};
...
...
@@ -2908,35 +2904,37 @@ struct YUV420p2RGBA8888Invoker
Mat
*
dst
;
const
uchar
*
my1
,
*
mu
,
*
mv
;
int
width
,
stride
;
int
ustepIdx
,
vstepIdx
;
YUV420p2RGBA8888Invoker
(
Mat
*
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
)
:
dst
(
_dst
),
my1
(
_y1
),
mu
(
_u
),
mv
(
_v
),
width
(
_dst
->
cols
),
stride
(
_stride
)
{}
YUV420p2RGBA8888Invoker
(
Mat
*
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
,
int
_ustepIdx
,
int
_vstepIdx
)
:
dst
(
_dst
),
my1
(
_y1
),
mu
(
_u
),
mv
(
_v
),
width
(
_dst
->
cols
),
stride
(
_stride
)
,
ustepIdx
(
_ustepIdx
),
vstepIdx
(
_vstepIdx
)
{}
void
operator
()(
const
BlockedRange
&
range
)
const
{
int
rangeBegin
=
range
.
begin
()
*
2
;
int
rangeEnd
=
range
.
end
()
*
2
;
//R = 1.164(Y - 16) + 1.596(V - 128)
//G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
//B = 1.164(Y - 16) + 2.018(U - 128)
//R = (1220542(Y - 16) + 1673527(V - 128) + (1 << 19)) >> 20
//G = (1220542(Y - 16) - 852492(V - 128) - 409993(U - 128) + (1 << 19)) >> 20
//B = (1220542(Y - 16) + 2116026(U - 128) + (1 << 19)) >> 20
const
int
cY
=
1220542
;
const
int
cUB
=
2116026
;
const
int
cUG
=
-
409993
;
const
int
cVG
=
-
852492
;
const
int
cVR
=
1673527
;
const
int
YUV420_SHIFT
=
20
;
size_t
uvsteps
[
2
]
=
{
width
/
2
,
stride
-
width
/
2
};
int
usIdx
=
ustepIdx
,
vsIdx
=
vstepIdx
;
const
uchar
*
y1
=
my1
+
rangeBegin
*
stride
;
const
uchar
*
u1
=
mu
+
(
range
.
begin
()
/
2
)
*
stride
+
(
range
.
begin
()
%
2
)
*
width
/
2
;
const
uchar
*
v1
=
mv
+
(
range
.
begin
()
/
2
)
*
stride
+
(
range
.
begin
()
%
2
)
*
width
/
2
;
const
uchar
*
u1
=
mu
+
(
range
.
begin
()
/
2
)
*
stride
;
const
uchar
*
v1
=
mv
+
(
range
.
begin
()
/
2
)
*
stride
;
if
(
range
.
begin
()
%
2
==
1
)
{
u1
+=
uvsteps
[(
usIdx
++
)
&
1
];
v1
+=
uvsteps
[(
vsIdx
++
)
&
1
];
}
for
(
int
j
=
rangeBegin
;
j
<
rangeEnd
;
j
+=
2
,
y1
+=
stride
*
2
,
u1
+=
width
/
2
,
v1
+=
width
/
2
)
for
(
int
j
=
rangeBegin
;
j
<
rangeEnd
;
j
+=
2
,
y1
+=
stride
*
2
,
u1
+=
uvsteps
[(
usIdx
++
)
&
1
],
v1
+=
uvsteps
[(
vsIdx
++
)
&
1
]
)
{
uchar
*
row1
=
dst
->
ptr
<
uchar
>
(
j
);
uchar
*
row2
=
dst
->
ptr
<
uchar
>
(
j
+
1
);
...
...
@@ -2975,12 +2973,6 @@ struct YUV420p2RGBA8888Invoker
row2
[
4
+
bIdx
]
=
saturate_cast
<
uchar
>
((
y11
+
buv
)
>>
YUV420_SHIFT
);
row2
[
7
]
=
uchar
(
0xff
);
}
if
(
j
%
4
==
2
)
{
u1
+=
stride
-
width
;
v1
+=
stride
-
width
;
}
}
}
};
...
...
@@ -3012,9 +3004,9 @@ inline void cvtYUV420sp2RGBA(Mat& _dst, int _stride, const uchar* _y1, const uch
}
template
<
int
bIdx
>
inline
void
cvtYUV420p2RGB
(
Mat
&
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
)
inline
void
cvtYUV420p2RGB
(
Mat
&
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
,
int
ustepIdx
,
int
vstepIdx
)
{
YUV420p2RGB888Invoker
<
bIdx
>
converter
(
&
_dst
,
_stride
,
_y1
,
_u
,
_v
);
YUV420p2RGB888Invoker
<
bIdx
>
converter
(
&
_dst
,
_stride
,
_y1
,
_u
,
_v
,
ustepIdx
,
vstepIdx
);
#ifdef HAVE_TBB
if
(
_dst
.
total
()
>=
MIN_SIZE_FOR_PARALLEL_YUV420_CONVERSION
)
parallel_for
(
BlockedRange
(
0
,
_dst
.
rows
/
2
),
converter
);
...
...
@@ -3024,9 +3016,9 @@ inline void cvtYUV420p2RGB(Mat& _dst, int _stride, const uchar* _y1, const uchar
}
template
<
int
bIdx
>
inline
void
cvtYUV420p2RGBA
(
Mat
&
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
)
inline
void
cvtYUV420p2RGBA
(
Mat
&
_dst
,
int
_stride
,
const
uchar
*
_y1
,
const
uchar
*
_u
,
const
uchar
*
_v
,
int
ustepIdx
,
int
vstepIdx
)
{
YUV420p2RGBA8888Invoker
<
bIdx
>
converter
(
&
_dst
,
_stride
,
_y1
,
_u
,
_v
);
YUV420p2RGBA8888Invoker
<
bIdx
>
converter
(
&
_dst
,
_stride
,
_y1
,
_u
,
_v
,
ustepIdx
,
vstepIdx
);
#ifdef HAVE_TBB
if
(
_dst
.
total
()
>=
MIN_SIZE_FOR_PARALLEL_YUV420_CONVERSION
)
parallel_for
(
BlockedRange
(
0
,
_dst
.
rows
/
2
),
converter
);
...
...
@@ -3461,15 +3453,19 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
int
srcstep
=
(
int
)
src
.
step
;
const
uchar
*
y
=
src
.
ptr
();
const
uchar
*
u
=
y
+
srcstep
*
dstSz
.
height
;
const
uchar
*
v
=
u
+
(
srcstep
*
dstSz
.
height
/
4
);
if
(
uidx
==
1
)
std
::
swap
(
u
,
v
);
const
uchar
*
v
=
y
+
srcstep
*
(
dstSz
.
height
+
dstSz
.
height
/
4
)
+
(
dstSz
.
width
/
2
)
*
((
dstSz
.
height
%
4
)
/
2
);
int
ustepIdx
=
0
;
int
vstepIdx
=
dstSz
.
height
%
4
==
2
?
1
:
0
;
if
(
uidx
==
1
)
{
std
::
swap
(
u
,
v
),
std
::
swap
(
ustepIdx
,
vstepIdx
);
};
switch
(
dcn
*
10
+
bidx
)
{
case
30
:
cvtYUV420p2RGB
<
0
>
(
dst
,
srcstep
,
y
,
u
,
v
);
break
;
case
32
:
cvtYUV420p2RGB
<
2
>
(
dst
,
srcstep
,
y
,
u
,
v
);
break
;
case
40
:
cvtYUV420p2RGBA
<
0
>
(
dst
,
srcstep
,
y
,
u
,
v
);
break
;
case
42
:
cvtYUV420p2RGBA
<
2
>
(
dst
,
srcstep
,
y
,
u
,
v
);
break
;
case
30
:
cvtYUV420p2RGB
<
0
>
(
dst
,
srcstep
,
y
,
u
,
v
,
ustepIdx
,
vstepIdx
);
break
;
case
32
:
cvtYUV420p2RGB
<
2
>
(
dst
,
srcstep
,
y
,
u
,
v
,
ustepIdx
,
vstepIdx
);
break
;
case
40
:
cvtYUV420p2RGBA
<
0
>
(
dst
,
srcstep
,
y
,
u
,
v
,
ustepIdx
,
vstepIdx
);
break
;
case
42
:
cvtYUV420p2RGBA
<
2
>
(
dst
,
srcstep
,
y
,
u
,
v
,
ustepIdx
,
vstepIdx
);
break
;
default
:
CV_Error
(
CV_StsBadFlag
,
"Unknown/unsupported color conversion code"
);
break
;
};
}
...
...
modules/imgproc/test/test_cvtyuv.cpp
0 → 100644
View file @
470f6faf
This diff is collapsed.
Click to expand it.
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