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
a35bec1e
Commit
a35bec1e
authored
Sep 16, 2016
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7293 from Algomorph:master
parents
aac745c8
0d626c8f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
2 deletions
+49
-2
cap_v4l.cpp
modules/videoio/src/cap_v4l.cpp
+49
-2
No files found.
modules/videoio/src/cap_v4l.cpp
View file @
a35bec1e
...
...
@@ -453,6 +453,10 @@ static int try_init_v4l2(CvCaptureCAM_V4L* capture, const char *deviceName)
}
static
int
autosetup_capture_mode_v4l2
(
CvCaptureCAM_V4L
*
capture
)
{
//in case palette is already set and works, no need to setup.
if
(
capture
->
palette
!=
0
and
try_palette_v4l2
(
capture
)){
return
0
;
}
__u32
try_order
[]
=
{
V4L2_PIX_FMT_BGR24
,
V4L2_PIX_FMT_YVU420
,
...
...
@@ -466,7 +470,8 @@ static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture) {
V4L2_PIX_FMT_SN9C10X
,
V4L2_PIX_FMT_SBGGR8
,
V4L2_PIX_FMT_SGBRG8
,
V4L2_PIX_FMT_RGB24
V4L2_PIX_FMT_RGB24
,
V4L2_PIX_FMT_Y16
};
for
(
size_t
i
=
0
;
i
<
sizeof
(
try_order
)
/
sizeof
(
__u32
);
i
++
)
{
...
...
@@ -558,6 +563,7 @@ static int v4l2_num_channels(__u32 palette) {
case
V4L2_PIX_FMT_YVU420
:
case
V4L2_PIX_FMT_MJPEG
:
case
V4L2_PIX_FMT_JPEG
:
case
V4L2_PIX_FMT_Y16
:
return
1
;
case
V4L2_PIX_FMT_YUYV
:
case
V4L2_PIX_FMT_UYVY
:
...
...
@@ -573,6 +579,7 @@ static int v4l2_num_channels(__u32 palette) {
static
void
v4l2_create_frame
(
CvCaptureCAM_V4L
*
capture
)
{
CvSize
size
(
capture
->
form
.
fmt
.
pix
.
width
,
capture
->
form
.
fmt
.
pix
.
height
);
int
channels
=
3
;
int
depth
=
IPL_DEPTH_8U
;
if
(
!
capture
->
convert_rgb
)
{
channels
=
v4l2_num_channels
(
capture
->
palette
);
...
...
@@ -585,11 +592,16 @@ static void v4l2_create_frame(CvCaptureCAM_V4L *capture) {
case
V4L2_PIX_FMT_YVU420
:
size
.
height
=
size
.
height
*
3
/
2
;
// "1.5" channels
break
;
case
V4L2_PIX_FMT_Y16
:
if
(
!
capture
->
convert_rgb
){
depth
=
IPL_DEPTH_16U
;
}
break
;
}
}
/* Set up Image data */
cvInitImageHeader
(
&
capture
->
frame
,
size
,
IPL_DEPTH_8U
,
channels
);
cvInitImageHeader
(
&
capture
->
frame
,
size
,
depth
,
channels
);
/* Allocate space for pixelformat we convert to.
* If we do not convert frame is just points to the buffer
...
...
@@ -1089,6 +1101,15 @@ uyvy_to_rgb24 (int width, int height, unsigned char *src, unsigned char *dst)
cvtColor
(
Mat
(
height
,
width
,
CV_8UC2
,
src
),
Mat
(
height
,
width
,
CV_8UC3
,
dst
),
COLOR_YUV2BGR_UYVY
);
}
static
inline
void
y16_to_rgb24
(
int
width
,
int
height
,
unsigned
char
*
src
,
unsigned
char
*
dst
)
{
Mat
gray8
;
Mat
(
height
,
width
,
CV_16UC1
,
src
).
convertTo
(
gray8
,
CV_8U
,
0.00390625
);
cvtColor
(
gray8
,
Mat
(
height
,
width
,
CV_8UC3
,
dst
),
COLOR_GRAY2BGR
);
}
#ifdef HAVE_JPEG
/* convert from mjpeg to rgb24 */
...
...
@@ -1546,6 +1567,18 @@ static IplImage* icvRetrieveFrameCAM_V4L( CvCaptureCAM_V4L* capture, int) {
(
unsigned
char
*
)
capture
->
buffers
[(
capture
->
bufferIndex
+
1
)
%
capture
->
req
.
count
].
start
,
(
unsigned
char
*
)
capture
->
frame
.
imageData
);
break
;
case
V4L2_PIX_FMT_Y16
:
if
(
capture
->
convert_rgb
){
y16_to_rgb24
(
capture
->
form
.
fmt
.
pix
.
width
,
capture
->
form
.
fmt
.
pix
.
height
,
(
unsigned
char
*
)
capture
->
buffers
[
capture
->
bufferIndex
].
start
,
(
unsigned
char
*
)
capture
->
frame
.
imageData
);
}
else
{
memcpy
((
char
*
)
capture
->
frame
.
imageData
,
(
char
*
)
capture
->
buffers
[
capture
->
bufferIndex
].
start
,
capture
->
frame
.
imageSize
);
}
break
;
}
return
(
&
capture
->
frame
);
...
...
@@ -1764,6 +1797,20 @@ static int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture,
capture
->
convert_rgb
=
bool
(
value
)
&&
possible
;
retval
=
possible
||
!
bool
(
value
);
break
;
case
CV_CAP_PROP_FOURCC
:
{
__u32
old_palette
=
capture
->
palette
;
__u32
new_palette
=
static_cast
<
__u32
>
(
value
);
capture
->
palette
=
new_palette
;
if
(
v4l2_reset
(
capture
))
{
retval
=
true
;
}
else
{
capture
->
palette
=
old_palette
;
v4l2_reset
(
capture
);
retval
=
false
;
}
}
break
;
default
:
retval
=
icvSetControl
(
capture
,
property_id
,
value
);
break
;
...
...
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