tensorrtx icon indicating copy to clipboard operation
tensorrtx copied to clipboard

Bounding box is not stable

Open lencm opened this issue 1 year ago • 0 comments

Env

  • GPU, Xavier ORIN
  • OS, Ubuntu20.04
  • Cuda version 11.4
  • TensorRT version 8.4

About this repo

  • which branch/tag/commit are you using? yolov5-v5.0
  • which model? yolov5-v5

Your problem

我修改程序后来识别相机视频流,帧率在30fps,通过打印可以看到每帧置信度都在0.9以上。但是显示的视频中,画出的框时有时无下面是我取照片后的程序,显示通过全局变量detect_right_mat在主线程显示,视频流正常,很流畅,就是识别框时有时无, 麻烦您帮忙看下是什么原因,谢谢

while(g_bAcquisitionFlag)
    {
		if (!ui32FrameCount)
        {
            time(&lInit);
        }
        // Get a frame from Queue
        emStatus = GXDQBuf(g_hDevice, &pFrameBuffer, 1000);
        ui32FrameCount++;
		DxRaw8toRGB24Ex((unsigned char*)pFrameBuffer->pImgBuf, g_pRGBImageBuf, pFrameBuffer->nWidth, pFrameBuffer->nHeight, RAW2RGB_NEIGHBOUR, BAYERRG, false, DX_ORDER_BGR);
		memcpy(right_mat.data, g_pRGBImageBuf, pFrameBuffer->nHeight * pFrameBuffer->nWidth * 3 * sizeof(unsigned char));
		rwlock.wrlock();
		remap(right_mat, right_rectified_img, mapRx, mapRy, INTER_LINEAR);
		rwlock.unlock();
        fcount++;
        for (int b = 0; b < fcount; b++) {
			cv::Mat img = right_rectified_img;
            if (img.empty()) continue;
            cv::Mat pr_img = preprocess_img(img, INPUT_W, INPUT_H); // letterbox BGR to RGB
            int i = 0;
            for (int row = 0; row < INPUT_H; ++row) {
                uchar* uc_pixel = pr_img.data + row * pr_img.step;
                for (int col = 0; col < INPUT_W; ++col) {
                    data[b * 3 * INPUT_H * INPUT_W + i] = (float)uc_pixel[2] / 255.0;
                    data[b * 3 * INPUT_H * INPUT_W + i + INPUT_H * INPUT_W] = (float)uc_pixel[1] / 255.0;
                    data[b * 3 * INPUT_H * INPUT_W + i + 2 * INPUT_H * INPUT_W] = (float)uc_pixel[0] / 255.0;
                    uc_pixel += 3;
                    ++i;
                }
            }
        }
        doInference(*context, stream, buffers, data, prob, BATCH_SIZE);
		std::vector<std::vector<Yolo::Detection>> batch_res(fcount);
        for (int b = 0; b < fcount; b++) {
            auto& res = batch_res[b];
            nms(res, &prob[b * OUTPUT_SIZE], CONF_THRESH, NMS_THRESH);
        }
		cv::Mat img1 = right_rectified_img; 
        for (int b = 0; b < fcount; b++) {
            auto& res = batch_res[b];
			if (res.size() !=0)
			{
            for (size_t j = 0; j < res.size(); j++) {
                cv::Rect r = get_rect(img1, res[j].bbox);
				rwlock.wrlock();
				right_center = getCenterPoint(r);
				rwlock.unlock();
				rwlock.rdlock();
				cv::circle(img1,right_center,10,cv::Scalar(0,0,255),-1);
				rwlock.unlock();
                cv::rectangle(img1, r, cv::Scalar(0x27, 0xC1, 0x36), 2);
                cv::putText(img1, "Target", cv::Point(r.x, r.y - 4), cv::FONT_HERSHEY_SIMPLEX, 1.2, cv::Scalar(0, 0, 0), 3);
			}
			}
			else std::cout << "Right no target detection" << std::endl;
            //cv::imwrite("_" + file_names[f - fcount + 1 + b], img);
			rwlock.wrlock();
			detect_right_mat = img1;
			rwlock.unlock();
        }
		time(&lEnd);
        // Print acquisition info each second.
        if (lEnd - lInit >= 1)
        {
            printf("<Right detect FrameCount: %u >\n",ui32FrameCount);
            ui32FrameCount = 0;
		}
        fcount = 0;
		emStatus = GXQBuf(g_hDevice, pFrameBuffer);
		if (emStatus != GX_STATUS_SUCCESS)
		{
			GetErrorString(emStatus);
		}
	}

lencm avatar Sep 09 '22 08:09 lencm