Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Meta MAR Fast Boot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Qiyang Sun
Meta MAR Fast Boot
Commits
34964c36
Verified
Commit
34964c36
authored
8 months ago
by
Qiyang Sun
Browse files
Options
Downloads
Patches
Plain Diff
Vision hello can parse args
parent
683e341f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
recipes-vision/visionhellocc/files/src/main.cc
+87
-16
87 additions, 16 deletions
recipes-vision/visionhellocc/files/src/main.cc
recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz
+0
-0
0 additions, 0 deletions
recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz
with
87 additions
and
16 deletions
recipes-vision/visionhellocc/files/src/main.cc
+
87
−
16
View file @
34964c36
...
...
@@ -2,51 +2,122 @@
#include
<opencv2/opencv.hpp>
#include
<iostream>
#include
<unistd.h>
#include
<getopt.h>
#include
<string>
std
::
string
gst_pipeline
=
"libcamerasrc ! "
"video/x-raw,framerate=50/1,width=640,height=480 !"
"videoscale ! videoconvert ! appsink"
;
std
::
string
output_filename
=
"out.avi"
;
int
frames_to_cap
=
50
;
int
fps
=
25
;
bool
quiet
=
false
;
int
main
(
void
)
{
cv
::
VideoCapture
cap
(
"libcamerasrc ! "
"video/x-raw,framerate=50/1,width=640,height=480 !"
"videoscale ! videoconvert ! appsink"
,
cv
::
CAP_GSTREAMER
);
main
(
int
argc
,
char
*
argv
[])
{
static
struct
option
long_options
[]
=
{
{
"output"
,
required_argument
,
0
,
'o'
},
{
"frames"
,
required_argument
,
0
,
'f'
},
{
"fps"
,
required_argument
,
0
,
'F'
},
{
"pipeline"
,
required_argument
,
0
,
'p'
},
{
"quiet"
,
no_argument
,
0
,
'q'
},
{
"help"
,
no_argument
,
0
,
'h'
},
{
0
,
0
,
0
,
0
}
};
int
opt
,
option_index
=
0
;
while
((
opt
=
getopt_long
(
argc
,
argv
,
"o:f:F:p:qh?"
,
long_options
,
&
option_index
))
!=
-
1
)
{
switch
(
opt
)
{
case
'o'
:
output_filename
=
optarg
;
break
;
case
'f'
:
frames_to_cap
=
std
::
stoi
(
optarg
);
break
;
case
'F'
:
fps
=
std
::
stoi
(
optarg
);
break
;
case
'p'
:
gst_pipeline
=
optarg
;
case
'q'
:
quiet
=
true
;
break
;
case
'h'
:
case
'?'
:
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" options"
<<
std
::
endl
<<
"Options:"
<<
std
::
endl
<<
" -o, --output output filename (default: out.avi)"
<<
std
::
endl
<<
" -f, --frames frames to capture (default: 50)"
<<
std
::
endl
<<
" -F, --fps output frames per second (default: 25)"
<<
std
::
endl
<<
" -p, --pipeline gstreamer pipeline (default: <<PipelineEOF "
<<
std
::
endl
<<
" libcamerasrc ! "
<<
std
::
endl
<<
" video/x-raw,framerate=50/1,width=640,height=480 !"
<<
std
::
endl
<<
" videoscale ! videoconvert ! appsink"
<<
std
::
endl
<<
" PipelineEOF)"
<<
std
::
endl
<<
" -q, --quiet try to keep quiet"
<<
std
::
endl
<<
" -h, --help show this help"
<<
std
::
endl
;
return
0
;
default:
std
::
cerr
<<
"Bad argument"
<<
std
::
endl
<<
"Usage: "
<<
argv
[
0
]
<<
" [-o output_file] [-f frames_to_capture] [-F output_fps]"
<<
std
::
endl
<<
" [-p gst_pipeline] [-q] [-h]"
<<
std
::
endl
;
return
1
;
}
}
cv
::
VideoCapture
cap
(
gst_pipeline
,
cv
::
CAP_GSTREAMER
);
if
(
!
cap
.
isOpened
())
{
std
::
cerr
<<
"Error: Could not open video stream."
<<
std
::
endl
;
return
-
1
;
return
1
;
}
int
frame_width
=
static_cast
<
int
>
(
cap
.
get
(
cv
::
CAP_PROP_FRAME_WIDTH
));
int
frame_height
=
static_cast
<
int
>
(
cap
.
get
(
cv
::
CAP_PROP_FRAME_HEIGHT
));
cv
::
Size
size
(
frame_width
,
frame_height
);
std
::
cout
<<
"Frame size: "
<<
size
<<
std
::
endl
;
if
(
!
quiet
)
{
std
::
cout
<<
"Frame size: "
<<
size
<<
std
::
endl
;
}
cv
::
VideoWriter
result
(
"file.avi"
,
cv
::
VideoWriter
::
fourcc
(
'M'
,
'J'
,
'P'
,
'G'
),
10
,
size
);
cv
::
VideoWriter
result
(
output_filename
,
cv
::
VideoWriter
::
fourcc
(
'M'
,
'J'
,
'P'
,
'G'
),
fps
,
size
);
if
(
!
result
.
isOpened
())
{
std
::
cerr
<<
"Error: Could not open the output video file."
<<
std
::
endl
;
return
-
1
;
return
1
;
}
for
(
int
x
=
0
;
x
<
50
;
++
x
)
{
if
(
!
quiet
)
{
std
::
cout
<<
"Recording..."
<<
std
::
endl
;
std
::
cout
<<
"Captured frames: "
;
}
for
(
int
x
=
0
;
x
<
frames_to_cap
;
++
x
)
{
cv
::
Mat
frame
;
bool
ret
=
cap
.
read
(
frame
);
if
(
!
ret
)
{
std
::
cerr
<<
"Error: Could not read frame."
<<
std
::
endl
;
std
::
cerr
<<
std
::
endl
<<
"Error: Could not read frame."
<<
std
::
endl
;
break
;
}
result
.
write
(
frame
);
std
::
cout
<<
"Captured frame "
<<
x
<<
std
::
endl
;
if
(
!
quiet
)
{
std
::
cout
<<
x
<<
" "
;
}
}
std
::
cout
<<
"Completed."
<<
std
::
endl
;
if
(
!
quiet
)
{
std
::
cout
<<
"capture completed."
<<
std
::
endl
;
std
::
cout
<<
"Releasing output and capture..."
<<
std
::
endl
;
}
result
.
release
();
cap
.
release
();
if
(
!
quiet
)
{
std
::
cout
<<
"Completed."
<<
std
::
endl
;
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
recipes-vision/visionhellocc/files/visionhellocc-1.0.tar.gz
+
0
−
0
View file @
34964c36
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment