Core dump happend when use imwrite() on luckfox board
ENV: luckfox version:v1.4; luckfox pro max opencv version: v4.12.0
Code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <unistd.h> // sleep()
int main()
{
cv::Mat bgr_jpg;
bgr_jpg = cv::imread("cv_test.jpg", 1);
printf("cv imread cv jpg\n");
// cv::VideoWriter http;
// http.open("httpjpg", 7766);
// printf("cv open http jpg\n");
cv::imwrite("fpv_img.jpg", bgr_jpg);
printf("cv imwrite cv jpg\n");
return 0;
}
Error: core dump log here:
[root@luckfox ~]# ./rv1106_ai_fpv_rtsp
opencv-mobile HW JPG encoder with rk mpp
[[22169.143673] mpp_vcodec: 45: num_chan = 0
rv1106_ai_fpv][main]:cv imread cv jpg
[22169.143773] mpp_vcodec: 103: create channel 0 handle 7760126e online 0
[rv1106_ai_fpv][main]:cv open http jpg
[22169.144461] 836: MPP_ENC_SET_CFG in
[rv1106_ai_fpv][main]:cv imwrite cv jpg
[22169.144483] 532: MPP_ENC_SET_RC_CFG bps 0 [0 : 0] fps [1:1] gop 1
[rv1106_ai_fpv][main]:cv g_main_run_
mpp[3941]: mpp_buffer: mpi_buf_id = 216, dma_buf_fd = 5
mpp[3941]: mpp: mClientFd 7 open ok attr.chan_id 0
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
[22169.201645] mpp_vcodec: 162: destroy chan 0 hnd 7760126e online 0 combo -1 mst -1
[22169.201771] mpp_vcodec: 188: destroy chan 0 done
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
streaming at http://127.0.0.1:7766
streaming at http://192.168.0.121:7766
streaming at http://172.32.0.93:7766
streaming at http://127.0.0.1:7766
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
mpp[3941]: mpp_frame: check_is_mpp_frame pointer 0x102594 failed on check
Segmentation fault (core dumped)
Hi @wallEVA96! I'm Dosu and I’m helping the opencv-mobile team.
The segmentation fault when using cv::imwrite() on Luckfox boards with the HW JPG encoder (rk mpp) is likely caused by invalid input to the hardware encoder—most commonly, an empty or improperly initialized cv::Mat (for example, if cv::imread() fails to load the image) or a memory layout the encoder can't handle. The hardware JPEG routines in opencv-mobile do check for empty/invalid Mats and image continuity, but low-level encoder errors may still result in a crash if the input isn't valid or compatible with the hardware requirements [PR #189].
To avoid this, always check that your image is loaded successfully before calling imwrite():
bgr_jpg = cv::imread("cv_test.jpg", 1);
if (bgr_jpg.empty()) {
printf("Failed to load image\n");
return -1;
}
cv::imwrite("fpv_img.jpg", bgr_jpg);
Recent updates in opencv-mobile improved stability by using temporary Mats for color conversion and falling back to software encoding if hardware encoding fails [PR #53], [PR #189]. If you still see crashes, try building with the latest version and ensure your build enables the correct hardware encoder flags for your platform.
If the hardware encoder fails, opencv-mobile should fall back to software encoding, but if the input is invalid, a segmentation fault can still occur. Validating your input image and ensuring it matches the expected format and memory layout for the encoder is the most reliable workaround.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@dosu The patch can‘’t fix issue.
Hi @wallEVA96! I'm Dosu and I’m helping the opencv-mobile team.
The segmentation fault when using
cv::imwrite()on Luckfox boards with the HW JPG encoder (rk mpp) is likely caused by invalid input to the hardware encoder—most commonly, an empty or improperly initializedcv::Mat(for example, ifcv::imread()fails to load the image) or a memory layout the encoder can't handle. The hardware JPEG routines in opencv-mobile do check for empty/invalid Mats and image continuity, but low-level encoder errors may still result in a crash if the input isn't valid or compatible with the hardware requirements [PR #189].To avoid this, always check that your image is loaded successfully before calling
imwrite():bgr_jpg = cv::imread("cv_test.jpg", 1); if (bgr_jpg.empty()) { printf("Failed to load image\n"); return -1; } cv::imwrite("fpv_img.jpg", bgr_jpg);
Recent updates in opencv-mobile improved stability by using temporary Mats for color conversion and falling back to software encoding if hardware encoding fails [PR #53], [PR #189]. If you still see crashes, try building with the latest version and ensure your build enables the correct hardware encoder flags for your platform.
If the hardware encoder fails, opencv-mobile should fall back to software encoding, but if the input is invalid, a segmentation fault can still occur. Validating your input image and ensuring it matches the expected format and memory layout for the encoder is the most reliable workaround.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
![]()
The segmentation fault can still happen even with the patch because the error handling in opencv-mobile’s hardware JPEG encoder (rk mpp) is limited—if the encoder crashes internally (for example, due to unexpected or incompatible image data), the fallback to software encoding never gets triggered and a core dump occurs instead. The code checks for image type and memory continuity, but does not explicitly check for empty Mats or all possible invalid states before calling the hardware encoder, and there’s no detailed logging or exception handling for hardware failures—just return code checks, which can’t catch all low-level faults (source).
To troubleshoot: double-check that your input image is valid (non-empty, correct type, continuous memory), and try saving a very simple test image (like a small, manually created Mat) to see if the crash still occurs. If it does, the issue is likely deep in the hardware encoder or its integration. If you can, try disabling hardware JPEG encoding to confirm if software encoding works as a workaround. If you have a stack trace or more detailed crash log, sharing that could help pinpoint exactly where the fault happens. There are currently no known fixes or workarounds for this specific crash in the opencv-mobile repo.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
I've got same issue enc_packet.offset always overflows here https://github.com/nihui/opencv-mobile/blob/19b882696349887dc2f301e959bee4dae06687ea/highgui/src/jpeg_encoder_rk_mpp.cpp#L933