Deepstream YOLO v5 outputs the detection results of the corresponding camera

I used Deepstream-5.1 on Jeston Nano to perform YOLO v5 detection, and I modified nvdsparsebbox_ The static bool NvDsInferParseYoloV5() function in the Yolo.cpp file can save the detection results in real-time as text and communicate through serial port. But when I use two cameras as input sources, how can I modify the code to include the corresponding camera information when saving the detection results, to clarify which camera’s image the detection results come from.

static bool NvDsInferParseYoloV5(
std::vector const& outputLayersInfo,
NvDsInferNetworkInfo const& networkInfo,
NvDsInferParseDetectionParams const& detectionParams,
std::vector& objectList)
{

char string[1024];
int i = 0;
int fd;
int num_flag = 0;
 static int count_usat = 0;
if (count_usat == 0)
{
	count_usat = 1;

fd = open (“/dev/ttyTHS1”, O_RDWR);
if (fd == -1)
{

    perror ("serialport error\n");  
   
}  
else  
{ 

    printf ("open ");  
    printf ("%s", ttyname (fd));  
    printf (" succesfully\n");  

}  


 

set_speed (fd, 115200);  
if (set_Parity (fd, 8, 1, 'N') == FALSE)  
{  
    printf ("Set Parity Error\n");  
    exit (0);  
}  
}

 

FILE * file_1 = fopen("labels.txt", "r");
if(file_1 == NULL) //打开文件出错。
{
	printf("Failed to open file_1\n");
		return -1;
}

#if 1
static int frame_number=0;
frame_number++;
char* cstr = new char[120];
sprintf(cstr, “%s%d%s”, “output/deepstream_output_”,frame_number , “.txt”);

FILE *fp = fopen(cstr, "a+");
if (fp == NULL)
{
	printf("Failed to open file\n");
	//return 0;
}
fseek(fp, 0, SEEK_SET);

endif

if (2 != detectionParams.numClassesConfigured)
{
    std::cerr << "WARNING: Num classes mismatch. Configured:"
              << detectionParams.numClassesConfigured
              << ", detected by network: " << 2 << std::endl;
}



std::vector<Detection> res;

nms(res, (float*)(outputLayersInfo[0].buffer), 0.25, kNMS_THRESH);
//std::cout<<"Nms done sucessfully----"<<std::endl;

//fseek(file_1, 0, SEEK_SET);
for(auto& r : res) {
NvDsInferParseObjectInfo oinfo;
oinfo.classId = r.class_id;
oinfo.left = static_cast(r.bbox[0]-r.bbox[2]*0.5f);
oinfo.top = static_cast(r.bbox[1]-r.bbox[3]*0.5f);
oinfo.width = static_cast(r.bbox[2]);
oinfo.height = static_cast(r.bbox[3]);
oinfo.detectionConfidence = r.conf;

    int left=static_cast<unsigned int>(r.bbox[0]-r.bbox[2]*0.5f);
	int top=static_cast<unsigned int>(r.bbox[1]-r.bbox[3]*0.5f);
	int width=static_cast<unsigned int>(r.bbox[2]);
	int height=static_cast<unsigned int>(r.bbox[3]);
	int classId=r.class_id;
	float detectionConfidence=r.conf;
    //std::cout << static_cast<unsigned int>(r.bbox[0]) << "," << static_cast<unsigned int>(r.bbox[1]) << "," << static_cast<unsigned int>(r.bbox[2]) << "," 
    //          << static_cast<unsigned int>(r.bbox[3]) << "," << static_cast<unsigned int>(r.class_id) << "," << static_cast<float>(r.conf) << std::endl;
    
	//fprintf(fp, "%d\n", left);
	i=0;
	fseek(file_1, 0, SEEK_SET);
	while (fgets(string, 1024, file_1) != NULL) //读取数据到数组,直到文件结尾(返回EOF)
	{
		//printf("i=%d,%s\n",i, string);
		if(classId==i)
		{
			int len = strlen(string);
			//printf("i=%d,%s\n",i, string);
			string[len - 1] = '\0'; // 去掉换行符
			//printf("len=%d,i=%d,%s\n",len,i, string);
			break;
		}
		i++;
		
	}
	//fprintf(fp, "%4d,%4d,%4d,%4d,%4d,%10f,%s\n", left,top,width,height,classId,detectionConfidence,string);
	//printf("iiiiiiiiiiiiii=%d,%s\n",i, string);
	//fprintf(fp, "%s %4d %10f %4d %4d %4d %4d\n", string,classId,detectionConfidence,left*3,top*3,width*3,height*3);
	fprintf(fp, "%s %10f %4d %4d %4d %4d\n", string,detectionConfidence,left*3,top*3,width*3,height*3); 

      // 构建输出字符串
    char outputStr[256];
    sprintf(outputStr, "F%dC%dL%dT%dW%dH%dE",
    frame_number, classId, left, top, width, height);

  // 将字符串写入串口
    int n = write(fd, outputStr, strlen(outputStr));
     num_flag =1;
	objectList.push_back(oinfo);        
}
if(num_flag == 1)
{
  char outputStr[256];
  sprintf(outputStr, "N\n");
  int n = write(fd, outputStr, strlen(outputStr));
}
fclose(file_1);//关闭文件	
fclose(fp);

return true;

}
strong text

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

This function is not a proper place.

The source id is in the frame meta and bbox is available in object meta. MetaData in the DeepStream SDK — DeepStream documentation 6.4 documentation
You may refer to /opt/sources/apps/sample_apps/deepstream-test2 for how to get object meta with probe function.

https://docs.nvidia.com/metropolis/deepstream/dev-guide/sdk-api/struct__NvDsFrameMeta.html
https://docs.nvidia.com/metropolis/deepstream/dev-guide/sdk-api/struct__NvDsObjectMeta.html

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.