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;
CreateCalibrationGpuMat("/mnt/calib.xml");
}
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!

Hi,

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?

Thanks.

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>
#include
class CRemapTest
{
public:
CRemapTest(const char* _sIndex,cv::cuda::GpuMat* _pGpuMat);
private:
void CreateCalibrationGpuMat();
void run();
private:
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;
CreateCalibrationGpuMat();
std::thread* pThread = new std::thread(&CRemapTest::run,this);
pThread->detach();
}
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);
tmp.download(tmp1);
cv::imshow(m_sIndex, tmp1);
cv::waitKey(1);
}
}
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();
mNewIntrinsicMat.at(0, 0) *= 0.8;
mNewIntrinsicMat.at(1, 1) = 0.8;
mNewIntrinsicMat.at(0, 2) = 0.5 * 1920;
mNewIntrinsicMat.at(1, 2) = 0.35 * 1080;
cv::fisheye::initUndistortRectifyMap(mIntrinsicMatrix, vDistortionCoeffs, cv::Matx33d::eye(), mNewIntrinsicMat, cv::Size(1920,1080), CV_32FC1, xMat, yMat);
}
if (!xMat.empty())
{
m_mXCalibrationGpuMat.upload(xMat);
}
if (!yMat.empty())
{
m_mYCalibrationGpuMat.upload(yMat);
}
}
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));
CRemapTest
p1 = new CRemapTest(“1”, &gpuMat1);
CRemapTest
p2 = new CRemapTest(“2”, &gpuMat2);
getchar();
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.