Page 1 of 3
OpenCV Mobile snapshot via RTSP
Posted: 2024-02-03 19:15
by Yurii
How to transfer images from OpenCV Mobile to RTSP server to view images online.
Could you please provide an example of the code?
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-04 6:45
by Eng33
After Chinese New Year, we may provide related example
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-04 8:29
by Yurii
Declared characteristics (Image Processor (ISP) Max input 5M @30fps)!
I get only 8 fps from the opencv-mobile example.
An example is reading 100 images with a resolution of 2304 x 1296
and I save only the last one for drawing fps on picture. I do not use any delays!
This it normal to not expect more?
Code: Select all
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include <unistd.h> // sleep()
#include <chrono>
int main()
{ //size = 32 x 16 ~ 2304 x 1296 (+8 +8)
cv::VideoCapture cap;
cap.set(cv::CAP_PROP_FRAME_WIDTH, 2304);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1296);
cap.open(0);
if (!cap.isOpened()) {
fprintf(stderr, "Error: Cannot open camera\n");
return -1;
}
const int w = cap.get(cv::CAP_PROP_FRAME_WIDTH);
const int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
fprintf(stderr, "%d x %d\n", w, h);
cv::Mat frame;
// Ініціалізуйте змінні для підрахунку кадрів та часу
int frame_count = 0;
std::chrono::time_point<std::chrono::steady_clock> start_time = std::chrono::steady_clock::now();
while ( 100 > frame_count)
{
cap >> frame;
// sleep(1);
if (frame.empty()) {
fprintf(stderr, "Error: Cannot grab frame\n");
break;
}
// Збільште кількість кадрів
frame_count++;
// Обчислення часу, що минув з початку захоплення
std::chrono::time_point<std::chrono::steady_clock> current_time = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_time = current_time - start_time;
// Обчислення FPS
double fps = frame_count / elapsed_time.count();
// Додайте текст FPS до кадру
cv::putText(frame, "FPS: " + std::to_string(fps), cv::Point(10, 50),
cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0), 2);
if(frame_count >98 ){ cv::imwrite("Video"+ std::to_string(frame_count)+".jpg", frame);}
}
cap.release();
return 0;
}
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-05 3:59
by Eng38
The problem is related to the program implementation. While you haven't used delays, the process of converting the image to JPG format and performing operations like saving and reading images is typically time-consuming. These operations may lead to a lower frame rate.
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-05 11:04
by Yurii
Eng38 wrote: ↑2024-02-05 3:59
The problem is related to the program implementation. While you haven't used delays, the process of converting the image to JPG format and performing operations like saving and reading images is typically time-consuming. These operations may lead to a lower frame rate.
How to work at all if you don't read the image? Please provide an example of code where I can read a 2304 x 1296 image at 30fps opencv-mobile. Is it just advertising?
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-05 11:57
by Eng38
It is recommended to reduce the resolution to increase the frame rate.
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-05 12:55
by Yurii
I need to know the exact capabilities of this board.
People need to know what to expect!
I know with yolo5 have maximum ~12fps.
I need to know the maximum fps with opencv-mobile and SC3336 2304 x 1296 ?
I don't want to spread false information!
So give a clear answer .
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-23 10:24
by Crocodile
Yurii wrote: ↑2024-02-05 12:55
I need to know the exact capabilities of this board.
People need to know what to expect!
I know with yolo5 have maximum ~12fps.
I need to know the maximum fps with opencv-mobile and SC3336 2304 x 1296 ?
I don't want to spread false information!
So give a clear answer .
Hello, thank you for your interest in the performance of Luckfox cameras.
Here's a routine that captures images at a resolution of 2304*1296 and calculates the frame rate using OpenCV-Mobile, displaying it in the top left corner, and streaming it. On the Luckfox-Pico Pro, it has been tested to achieve around 22 frames per second.
https://github.com/luckfox-eng29/luckfo ... tsp_opencv
Please note that this routine captures images from the camera by invoking the VI module in RKMPI instead of directly using OpenCV-Mobile. During streaming, VENC is used to encode the video into H264, which introduces some latency.You can refer to it(Unfortunately, this document is not available in English).
If you wish to test its maximum performance, you can improve it by.For example, using your own rtspserver library, adjusting encoding quality, and other methods.
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-23 19:52
by Yurii
Thank you.
Can you tell me how to compile the program in more detail?
I have problems when compiling with VScode.
Re: OpenCV Mobile snapshot via RTSP
Posted: 2024-02-24 3:08
by Crocodile
Yurii wrote: ↑2024-02-23 19:52
Thank you.
Can you tell me how to compile the program in more detail?
I have problems when compiling with VScode.
You can obtain the source code via git and refer to the README for compilation instructions.
Code: Select all
git clone https://github.com/luckfox-eng29/luckfox_pico_rtsp_opencv.git
cd luckfox_pico_rtsp_opencv
export LUCKFOX_SDK_PATH=<Your Luckfox-pico Sdk Path>
mkdir build
cd build
cmake ..
make && make install
The compiled executable file is stored in the
<project>/luckfox_rtsp_opencv_demo folder for your testing purposes.