Application source code runtime error "Segmentation fault" please help

Which Khadas SBC do you use?

vim3 pro

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu 22.04 , 5.15

Which version of system do you use? Khadas official images, self built images, or others?

Please describe your issue below:

Hello, Khadas Team I encountered the following error while performing an application source code demo. The conversion was successful using the model I trained, but a segmentation error occurred during runtime. The number of classes in my model is 8, so I modified yolo_tiny_process.c’s class_num = 8 and coco_name to 8 as well. Why does the following error occur? Please tell me how to solve it.

Post a console log of your issue below:

Typically its a pointer issue / array / buffer in c. It could be many issues, set some printf statements where you might suspect the issue. That will let you narrow it down to the function that needs a little help. I have not used the package you are working on so keep that in mind too.

1 Like

I think I need to modify main.cpp, but I can’t figure out where and how to printf

I solved this problem


85*3 → (8+5)*3

Hello @chaneo

Could you provide your model?

1 Like

I just solved this problem


I only changed the class_num value and did not change 85 * 3
So I changed 85 * 3 to 13 * 3 and it run successly

85*3 → (8+5)*3

Thank you so much for your reply. :slight_smile:

Hello @chaneo ,

Could you provide your model and a picture to test?


Sorry, but I think it would be difficult to provide a my model. Can you tell me what the source code for setting the ROI area is? I’m going to try to fix that myself

Hello @chaneo ,

Our code does not add ROI area. It detects the whole picture. You can add it by yourself.

From your result picture, the result box is much bigger than the picture. I guess that problem is decoding result from model to picture.

In main.cpp, here is the code from getting output to drawing result.

		ret = det_get_result(&resultData, g_model_type); # get model outputs
		if (ret) {
			cout << "det_get_result fail. ret=" << ret << endl;
			goto out;

		gettimeofday(&time_end, 0);
		draw_results(img, resultData, width, height, g_model_type); # decode output and draw on picture
1 Like


I am not using pictures but rather recognizing objects through images via RTSP.

In the current video, only the bottom half is recognized as an object and the top half is not. How can I add an ROI area?

Also, the boundary box cannot follow the moving object and is drawn in the wrong place.

Hello @chaneo ,

Our demo will detect the whole picture. All thing will be detected unless the model can not detect it.

I suggest you can modify main.cpp from detecting video to detecting picture, first. It is easier to find the problem. Detect one picture by nb model and original model. Compare the model output whether is similar. Make sure the quantized model is right.

1 Like

hello, @Louis-Cheng-Liu

I faced a new problem. Currently, I am importing video using rtsp. Objects are mainly recognized as cars. The boundary box was drawn appropriately around the object, but as the car got closer to the camera, the boundary box became too large. What could be the cause?

thank you.

Hello @chaneo ,

Sorry, from your description, i can not make sure waht is wrong with it.

Have you changed function draw_results? The width and height of draw_results input is true?

And could you provide the picture for far car right box and close car too large box?

Hello @Louis-Cheng-Liu

Yes, the width and height of the image are true.

Could you please look at the picture I drew below?
When a car approaches in the direction of travel, the bounding box becomes abnormally large. did you understand?

thank you

Hello @chaneo ,

It looks like decoding mistake. I suggest you print wrong box left, right, top and bottom. Make sure the wrong box loaction in picture corresponds to result.

And have you done other changes for main.cpp? Before this problem, is all the result is right?

Hello @Louis-Cheng-Liu

If it is a decoding problem, how do I solve it?
" suggest you print wrong box left, right, top and bottom. Make sure the wrong box loaction in picture corresponds to result." I didn’t quite understand what you said. I didn’t change any other parts of main.cpp. Before this problem, the other results come out right.

thank you

Hello @chaneo ,

I mean you should check decoding is right or not. First, check if the box’s left, right, top and bottom in picture is the same as the print left, right, top and bottom. If it is same, the decoding is right.

Hello @Louis-Cheng-Liu

Sorry “print left, right, top and bottom.” I don’t understand what this means. Could you please tell me the code where I can check it?

thank you

Hello @chaneo ,

Check whether the coordinate of point A and point B is same as draw_results left, right, top and bottom or not.

And could you provide the whole draw_results function?

To explain once again, when the camera is looking at a car on the road and recognizes a car far away, the bounding box is drawn accurately, but as the car approaches the camera, the bounding box becomes much larger compared to the size of the object.

it is my draw_results
static void draw_results(cv::Mat& frame, DetectResult resultData, int img_width, int img_height, det_model_type type){

int i = 0;
float left, right, top, bottom;

for (i = 0; i < resultData.detect_num; i++) {
left =  resultData.point[i].point.rectPoint.left*704;
    right = resultData.point[i].point.rectPoint.right*704;
    top = resultData.point[i]*480;
    bottom = resultData.point[i].point.rectPoint.bottom*480;

	cout << " left:" << resultData.point[i].point.rectPoint.left << endl;
	cout << " right:"<< resultData.point[i].point.rectPoint.right << endl;
	cout << " top:"  << resultData.point[i] << endl;
	cout << " bottom:" << resultData.point[i].point.rectPoint.bottom<< endl;

	cout << " frame cols : " << frame.cols << "frame rows : " << frame.rows << endl;
	cv::Rect rect(left, top, right-left, bottom-top);
	switch (type) {
		case DET_YOLO_V2:
		case DET_YOLO_V3:
		case DET_YOLO_V4:
			if (top < 50) {
				top = 50;
				left +=10;
			int baseline;
			cv::Size text_size = cv::getTextSize(resultData.result_name[i].lable_name, cv::FONT_HERSHEY_COMPLEX,0.5,1,&baseline);
			cv::Rect rect1(left, top-20, text_size.width+10, 20);			

cv::imshow("Image Window",frame);


and this is my result left , top , right , bottom