Set Raspberry Camera mode using OpenCV / C++
up vote
0
down vote
favorite
I'm trying to set the Raspberry Pi Cameras mode using OpenCVs VideoCapture class and setting it's properties with the code below. Setting it to 640x480x30fps works just fine, but 1920x1080x30 fps only delivers 3 or 4 frames per second.
Can anyone tell me what I'm missing? Thanks a lot.
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main (){
int height(1080);
int width(1920);
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
cap.set(cv::CAP_PROP_FOURCC, 0x21);
cap.set(cv::CAP_PROP_FPS, 30);
cv::Mat currentFrame;
while(1){
cap >> currentFrame;
//do stuff
char c = (char)cv::waitKey(1);
if (c == 27) break;
}
}
c++ performance opencv raspberry-pi screen-resolution
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I'm trying to set the Raspberry Pi Cameras mode using OpenCVs VideoCapture class and setting it's properties with the code below. Setting it to 640x480x30fps works just fine, but 1920x1080x30 fps only delivers 3 or 4 frames per second.
Can anyone tell me what I'm missing? Thanks a lot.
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main (){
int height(1080);
int width(1920);
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
cap.set(cv::CAP_PROP_FOURCC, 0x21);
cap.set(cv::CAP_PROP_FPS, 30);
cv::Mat currentFrame;
while(1){
cap >> currentFrame;
//do stuff
char c = (char)cv::waitKey(1);
if (c == 27) break;
}
}
c++ performance opencv raspberry-pi screen-resolution
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Have you tried increasing the FPS? I think this is a performance issue...
– Ruks
4 hours ago
The first thing to do is to remove the all the "stuff" that you do in the middle of the loop to see if the hardware is capable of simply acquiring and discarding frames at that rate. The next thing to do is benchmark how long the "stuff" takes on its own without acquiring any new data. Only when you know where the time is being used up can you start to optimise.
– Mark Setchell
2 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to set the Raspberry Pi Cameras mode using OpenCVs VideoCapture class and setting it's properties with the code below. Setting it to 640x480x30fps works just fine, but 1920x1080x30 fps only delivers 3 or 4 frames per second.
Can anyone tell me what I'm missing? Thanks a lot.
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main (){
int height(1080);
int width(1920);
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
cap.set(cv::CAP_PROP_FOURCC, 0x21);
cap.set(cv::CAP_PROP_FPS, 30);
cv::Mat currentFrame;
while(1){
cap >> currentFrame;
//do stuff
char c = (char)cv::waitKey(1);
if (c == 27) break;
}
}
c++ performance opencv raspberry-pi screen-resolution
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm trying to set the Raspberry Pi Cameras mode using OpenCVs VideoCapture class and setting it's properties with the code below. Setting it to 640x480x30fps works just fine, but 1920x1080x30 fps only delivers 3 or 4 frames per second.
Can anyone tell me what I'm missing? Thanks a lot.
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main (){
int height(1080);
int width(1920);
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
cap.set(cv::CAP_PROP_FOURCC, 0x21);
cap.set(cv::CAP_PROP_FPS, 30);
cv::Mat currentFrame;
while(1){
cap >> currentFrame;
//do stuff
char c = (char)cv::waitKey(1);
if (c == 27) break;
}
}
c++ performance opencv raspberry-pi screen-resolution
c++ performance opencv raspberry-pi screen-resolution
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 1 hour ago
Ruks
445111
445111
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 4 hours ago
TonySoprano
111
111
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
TonySoprano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Have you tried increasing the FPS? I think this is a performance issue...
– Ruks
4 hours ago
The first thing to do is to remove the all the "stuff" that you do in the middle of the loop to see if the hardware is capable of simply acquiring and discarding frames at that rate. The next thing to do is benchmark how long the "stuff" takes on its own without acquiring any new data. Only when you know where the time is being used up can you start to optimise.
– Mark Setchell
2 hours ago
add a comment |
Have you tried increasing the FPS? I think this is a performance issue...
– Ruks
4 hours ago
The first thing to do is to remove the all the "stuff" that you do in the middle of the loop to see if the hardware is capable of simply acquiring and discarding frames at that rate. The next thing to do is benchmark how long the "stuff" takes on its own without acquiring any new data. Only when you know where the time is being used up can you start to optimise.
– Mark Setchell
2 hours ago
Have you tried increasing the FPS? I think this is a performance issue...
– Ruks
4 hours ago
Have you tried increasing the FPS? I think this is a performance issue...
– Ruks
4 hours ago
The first thing to do is to remove the all the "stuff" that you do in the middle of the loop to see if the hardware is capable of simply acquiring and discarding frames at that rate. The next thing to do is benchmark how long the "stuff" takes on its own without acquiring any new data. Only when you know where the time is being used up can you start to optimise.
– Mark Setchell
2 hours ago
The first thing to do is to remove the all the "stuff" that you do in the middle of the loop to see if the hardware is capable of simply acquiring and discarding frames at that rate. The next thing to do is benchmark how long the "stuff" takes on its own without acquiring any new data. Only when you know where the time is being used up can you start to optimise.
– Mark Setchell
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
Have you ever tried playing a relatively modern game on a $100 graphics card? Same difference.
The Raspberry Pi doesn't have the processing power or memory capable of capturing high quality video. That's why 640x480 works fine, but as soon as you increase the resolution the FPS nosedives.
Optimization of your code could help, but there's a finite amount of processing power capable from your Raspberry Pi.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
This is heavily dependent on the memory and what you are asking is dependent on optimization, so, out of the many ways to optimize your code, you could do something like:
cv::Mat currentFrame;
cv::Mat lastFrame;
cap >> lastFrame;
while(1)
{
cap >> currentFrame;
// We skip the frame if it is equal to the last frame, minimally optimizing it to
// some extent...
if (currentFrame == lastFrame) continue;
if (currentFrame.empty()) break;
lastFrame = currentFrame;
//do stuff
if( cv::waitKey(1) == 27 ) break;
}
But remember, this doesn't mean that you don't have anything to do with your hardware, your processor is responsible for every kind of computation operation there is...
So, in order to render in high resolution, your processor has to have a high-end capacity power too, optimizing code is just to reduce CPU load...
See here,
1920 * 1080 * 30 = 62208000 pixels (More resolution, more memory)
640 * 480 * 30 = 9216000 pixles (Less resolution, less memory)
Your device has to render these pixels one by one so it is normal for the frame rate to drop, your computer has to have a great memory to compute 62208000 pixels for 1920x1080 in one second...
Edit: Also, I would like you to look at this article demonstrating why we prioritize frame rate over resolution...
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Have you ever tried playing a relatively modern game on a $100 graphics card? Same difference.
The Raspberry Pi doesn't have the processing power or memory capable of capturing high quality video. That's why 640x480 works fine, but as soon as you increase the resolution the FPS nosedives.
Optimization of your code could help, but there's a finite amount of processing power capable from your Raspberry Pi.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
Have you ever tried playing a relatively modern game on a $100 graphics card? Same difference.
The Raspberry Pi doesn't have the processing power or memory capable of capturing high quality video. That's why 640x480 works fine, but as soon as you increase the resolution the FPS nosedives.
Optimization of your code could help, but there's a finite amount of processing power capable from your Raspberry Pi.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
up vote
1
down vote
Have you ever tried playing a relatively modern game on a $100 graphics card? Same difference.
The Raspberry Pi doesn't have the processing power or memory capable of capturing high quality video. That's why 640x480 works fine, but as soon as you increase the resolution the FPS nosedives.
Optimization of your code could help, but there's a finite amount of processing power capable from your Raspberry Pi.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Have you ever tried playing a relatively modern game on a $100 graphics card? Same difference.
The Raspberry Pi doesn't have the processing power or memory capable of capturing high quality video. That's why 640x480 works fine, but as soon as you increase the resolution the FPS nosedives.
Optimization of your code could help, but there's a finite amount of processing power capable from your Raspberry Pi.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 3 hours ago
user9754798
162
162
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user9754798 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
up vote
0
down vote
This is heavily dependent on the memory and what you are asking is dependent on optimization, so, out of the many ways to optimize your code, you could do something like:
cv::Mat currentFrame;
cv::Mat lastFrame;
cap >> lastFrame;
while(1)
{
cap >> currentFrame;
// We skip the frame if it is equal to the last frame, minimally optimizing it to
// some extent...
if (currentFrame == lastFrame) continue;
if (currentFrame.empty()) break;
lastFrame = currentFrame;
//do stuff
if( cv::waitKey(1) == 27 ) break;
}
But remember, this doesn't mean that you don't have anything to do with your hardware, your processor is responsible for every kind of computation operation there is...
So, in order to render in high resolution, your processor has to have a high-end capacity power too, optimizing code is just to reduce CPU load...
See here,
1920 * 1080 * 30 = 62208000 pixels (More resolution, more memory)
640 * 480 * 30 = 9216000 pixles (Less resolution, less memory)
Your device has to render these pixels one by one so it is normal for the frame rate to drop, your computer has to have a great memory to compute 62208000 pixels for 1920x1080 in one second...
Edit: Also, I would like you to look at this article demonstrating why we prioritize frame rate over resolution...
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
add a comment |
up vote
0
down vote
This is heavily dependent on the memory and what you are asking is dependent on optimization, so, out of the many ways to optimize your code, you could do something like:
cv::Mat currentFrame;
cv::Mat lastFrame;
cap >> lastFrame;
while(1)
{
cap >> currentFrame;
// We skip the frame if it is equal to the last frame, minimally optimizing it to
// some extent...
if (currentFrame == lastFrame) continue;
if (currentFrame.empty()) break;
lastFrame = currentFrame;
//do stuff
if( cv::waitKey(1) == 27 ) break;
}
But remember, this doesn't mean that you don't have anything to do with your hardware, your processor is responsible for every kind of computation operation there is...
So, in order to render in high resolution, your processor has to have a high-end capacity power too, optimizing code is just to reduce CPU load...
See here,
1920 * 1080 * 30 = 62208000 pixels (More resolution, more memory)
640 * 480 * 30 = 9216000 pixles (Less resolution, less memory)
Your device has to render these pixels one by one so it is normal for the frame rate to drop, your computer has to have a great memory to compute 62208000 pixels for 1920x1080 in one second...
Edit: Also, I would like you to look at this article demonstrating why we prioritize frame rate over resolution...
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
This is heavily dependent on the memory and what you are asking is dependent on optimization, so, out of the many ways to optimize your code, you could do something like:
cv::Mat currentFrame;
cv::Mat lastFrame;
cap >> lastFrame;
while(1)
{
cap >> currentFrame;
// We skip the frame if it is equal to the last frame, minimally optimizing it to
// some extent...
if (currentFrame == lastFrame) continue;
if (currentFrame.empty()) break;
lastFrame = currentFrame;
//do stuff
if( cv::waitKey(1) == 27 ) break;
}
But remember, this doesn't mean that you don't have anything to do with your hardware, your processor is responsible for every kind of computation operation there is...
So, in order to render in high resolution, your processor has to have a high-end capacity power too, optimizing code is just to reduce CPU load...
See here,
1920 * 1080 * 30 = 62208000 pixels (More resolution, more memory)
640 * 480 * 30 = 9216000 pixles (Less resolution, less memory)
Your device has to render these pixels one by one so it is normal for the frame rate to drop, your computer has to have a great memory to compute 62208000 pixels for 1920x1080 in one second...
Edit: Also, I would like you to look at this article demonstrating why we prioritize frame rate over resolution...
This is heavily dependent on the memory and what you are asking is dependent on optimization, so, out of the many ways to optimize your code, you could do something like:
cv::Mat currentFrame;
cv::Mat lastFrame;
cap >> lastFrame;
while(1)
{
cap >> currentFrame;
// We skip the frame if it is equal to the last frame, minimally optimizing it to
// some extent...
if (currentFrame == lastFrame) continue;
if (currentFrame.empty()) break;
lastFrame = currentFrame;
//do stuff
if( cv::waitKey(1) == 27 ) break;
}
But remember, this doesn't mean that you don't have anything to do with your hardware, your processor is responsible for every kind of computation operation there is...
So, in order to render in high resolution, your processor has to have a high-end capacity power too, optimizing code is just to reduce CPU load...
See here,
1920 * 1080 * 30 = 62208000 pixels (More resolution, more memory)
640 * 480 * 30 = 9216000 pixles (Less resolution, less memory)
Your device has to render these pixels one by one so it is normal for the frame rate to drop, your computer has to have a great memory to compute 62208000 pixels for 1920x1080 in one second...
Edit: Also, I would like you to look at this article demonstrating why we prioritize frame rate over resolution...
edited 2 hours ago
answered 3 hours ago
Ruks
445111
445111
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
add a comment |
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
Not sure I "see" your optimisation, it represents a bigger CPU load than the OP's question as you are comparing 62 megapixels per frame. Also, it is virtually certain that no two frames will be identical even in a still scene - lighting flickers, noise occurs...
– Mark Setchell
2 hours ago
add a comment |
TonySoprano is a new contributor. Be nice, and check out our Code of Conduct.
TonySoprano is a new contributor. Be nice, and check out our Code of Conduct.
TonySoprano is a new contributor. Be nice, and check out our Code of Conduct.
TonySoprano is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203345%2fset-raspberry-camera-mode-using-opencv-c%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Have you tried increasing the FPS? I think this is a performance issue...
– Ruks
4 hours ago
The first thing to do is to remove the all the "stuff" that you do in the middle of the loop to see if the hardware is capable of simply acquiring and discarding frames at that rate. The next thing to do is benchmark how long the "stuff" takes on its own without acquiring any new data. Only when you know where the time is being used up can you start to optimise.
– Mark Setchell
2 hours ago