Issue with multiple threads for cv::cuda::remap in cv_process,the content Probabilistic disorder

for example,two cameras ,two decode threads,remap the decoded frame in cv_process,like this
void CNvTX2Decoder::cv_process(void *pdata, int32_t width, int32_t height)
if(m_nFirst == 0)
m_nFirst = 1;
cv::cuda::GpuMat d_mat(height, width, CV_8UC4, pdata);
cv::cuda::remap(d_mat, d_mat, m_mXCalibrationGpuMat, m_mYCalibrationGpuMat, cv::INTER_LINEAR, cv::BORDER_CONSTANT);
when display,images of two windows may replace each other. i have to block the thread when cv::cuda::remap. for example 8 cameras,The delay time will fluctuate greatly.
For multithreaded calls to remap, the same problem occurs on the PC. is there any other solutions?Could someone help me? Best wishes to you all!


Suppose you show the output in the tiler mode.
Do you mark the pipeline with some index so you can tell the source of each output?


Do you guess that the display does not correspond to the channel?
This possibility can be ruled out.Basically, i guess,it is the problem of remap function. for test ,on pc ,the content disorder. on tx2nx,it can only display one window(only new one CRemapTest,the complie is :g++ demo.cpp pkg-config --libs --cflags opencv4 -lpthread -o demo).

#include <opencv2/opencv.hpp>
class CRemapTest
CRemapTest(const char* _sIndex,cv::cuda::GpuMat* _pGpuMat);
void CreateCalibrationGpuMat();
void run();
cv::cuda::GpuMat m_mXCalibrationGpuMat, m_mYCalibrationGpuMat;
cv::String m_sIndex;
cv::cuda::GpuMat* m_pGpuMat = NULL;
CRemapTest::CRemapTest(const char* _sIndex, cv::cuda::GpuMat* _pGpuMat)
m_sIndex = cv::String(_sIndex);
m_pGpuMat = pGpuMat;
std::thread* pThread = new std::thread(&CRemapTest::run,this);
void CRemapTest::run()
//cv::namedWindow(m_sIndex, cv::WINDOW_OPENGL);
cv::namedWindow(m_sIndex, cv::WINDOW_NORMAL);
while (1)
cv::cuda::GpuMat tmp;
cv::Mat tmp1;
cv::cuda::remap(*m_pGpuMat, tmp, m_mXCalibrationGpuMat, m_mYCalibrationGpuMat, cv::INTER_LINEAR, cv::BORDER_CONSTANT);;
cv::imshow(m_sIndex, tmp1);
void CRemapTest::CreateCalibrationGpuMat()
cv::Mat xMat, yMat;
cv::Mat mIntrinsicMatrix;
cv::Mat mNewIntrinsicMat;
cv::Vec4d vDistortionCoeffs;
mIntrinsicMatrix = (cv::Mat
(3, 3) << 6.7785194011952501e+02, 0., 1.0045177933316378e+03, 0., 6.8042887270726499e+02, 4.8603949578811273e+02, 0., 0., 1.);
vDistortionCoeffs = cv::Vec4d(0, 0, 0, 0);
mNewIntrinsicMat = mIntrinsicMatrix.clone();, 0) *= 0.8;, 1) = 0.8;, 2) = 0.5 * 1920;, 2) = 0.35 * 1080;
cv::fisheye::initUndistortRectifyMap(mIntrinsicMatrix, vDistortionCoeffs, cv::Matx33d::eye(), mNewIntrinsicMat, cv::Size(1920,1080), CV_32FC1, xMat, yMat);
if (!xMat.empty())
if (!yMat.empty())
int main(int argc, char argv[])
cv::cuda::GpuMat gpuMat1, gpuMat2;
gpuMat1 = cv::cuda::GpuMat(1080, 1920, CV_8UC4, cv::Scalar(255, 0, 0, 255));
gpuMat2 = cv::cuda::GpuMat(1080, 1920, CV_8UC4, cv::Scalar( 0, 0, 255, 255));
p1 = new CRemapTest(“1”, &gpuMat1);
p2 = new CRemapTest(“2”, &gpuMat2);
return 0;

use the remap api with cv::cuda::Stream,which is in the Corresponding thread

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