c++ - OpenCV Segmentation fault (core dumped) While Using cv::Mat::at -


i trying map cv::mat pixels float4* cuda computation.

cv::mat frame = cv::imread("peds-007.png", cv::imread_color);  cudaallocmapped((void**) cpu, (void**) gpu,                 frame.cols * frame.rows * sizeof(float) * 4);  float4* cpuptr = *cpu; (uint32_t y = 0; y < frame.rows; y++) {     (uint32_t x = 0; x < frame.cols; x++) {         std::cout << x << ", " << y << std::endl;         const float4 px = make_float4(float(frame.at<cv::vec3b>(x, y)[2]),                                       float(frame.at<cv::vec3b>(x, y)[1]),                                       float(frame.at<cv::vec3b>(x, y)[0]),                                       float(255));                                       //float(frame.at<cv::vec4b>(x, y)[3]));                  cpuptr[y*imgwidth+x] = px;     } } 

if run above code, got segmentation fault (core dumped).

the last pixel accessed code @ (1662, 0).

if directly access pixel outside loop:

frame.at<cv::vec3b>(1662, 0); 

it causes segmentation fault (core dumped).

why happen , how can solve problem?

cv::mat indexed in row-major order. reverse x's , y's.

const float4 px = make_float4(float(frame.at<cv::vec3b>(y,x)[2]),                               float(frame.at<cv::vec3b>(y,x)[1]),                               float(frame.at<cv::vec3b>(y,x)[0]),                               float(255)); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -