How to retain what i have drawn on the next frame

TX2 DS4.0.0
i draw and show the frame with opencv, but on the next frame, what i have drawn on the previous frame disappeared.

memset(&map_info, 0, sizeof(map_info));
if (gst_buffer_map(buf, &map_info, GST_MAP_READWRITE)){

	batch_meta = gst_buffer_get_nvds_batch_meta(buf);

	for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next){
		frame_meta = (NvDsFrameMeta*)l_frame->data;

		surface = (NvBufSurface*)map_info.data;
		NvBufSurfaceMap(surface, -1, -1, NVBUF_MAP_READ_WRITE);
		NvBufSurfaceSyncForCpu(surface, -1, -1);
		surface->numFilled = surface->batchSize = 1;	// 

		gint frame_width = (gint)surface->surfaceList[frame_meta->batch_id].width;
		gint frame_height = (gint)surface->surfaceList[frame_meta->batch_id].height;
		void *frame_data = surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[0];
		size_t frame_step = surface->surfaceList[frame_meta->batch_id].pitch;
		
		cv::Mat frame = cv::Mat(frame_height, frame_width, CV_8UC4, frame_data, frame_step);
		cv::Mat frame_bgr = cv::Mat(cv::Size(frame_width, frame_height), CV_8UC3);
		cv::cvtColor(frame, frame_bgr, cv::COLOR_RGBA2BGR);
		cv::circle(frame_bgr, cv::Point(1000, 1000), 150, (0, 255, 0), 5);

		cv::cvtColor(frame_bgr, frame, cv::COLOR_BGR2RGBA);
	}
	NvBufSurfaceUnMap(surface, -1, -1);
}
gst_buffer_unmap(buf, &map_info);

Could you refer gstdsexample.cpp-> get_converted_mat

i hvae refered to, and the frame i changed only show on the right frame, when ii’t on next frame, the frame i changed recovered

I didn’t get your meaning, could you specify more details. how do you confirm the change only applied on current frame and recovered when next frame coming?

One thing you may need to note per your code, If the CPU modifies mapped memory, the client must call NvBufSurfaceSyncForDevice() before any hardware device accesses the memory.

i try to draw the trace of those cars, and it only show pts on the frame, and the pts of the former frame disappeared

how can i show continuous pts on the frame, which show the trace of the car

what’s pts? Are you trying to draw the trajectory of a moving car? If yes, I think you need to get the coordinates of the car in previous frames, and then draw the line.

i can get the oordinates of the car in previous frames, and i can draw the trajectory on this way.
and i wonder why the pts i drawd on the frame can’t show on next frame.

Every frame is a single buffer, you cannot expect the change on a former frame will be available on current frame.

i got it, thanks!