find "stream[imgNum]" error "std::vector<cv::Mat>…
- User
find "stream_[imgNum]" error "std::vectorcv::Mat Segmentator::process(std::vectorcv::Mat &frames) { std::vectorcv::Mat masksOut; masksOut.reserve(frames.size()); int imgNum {0}; int n_streams = frames.size(); streamAlloc(n_streams); for(cv::Mat& image : frames) { //resize input image to the size required by neural net cv::Mat image_resized(h_, w_, CV_8UC3, inputCpu_); if (up_crop_ != 0) { std::int16_t cropRows = image.rows - up_crop_; cv::Rect crop(0, up_crop_, image.cols, cropRows); cv::Mat img_crop = image(crop); cv::resize(img_crop, image_resized, cv::Size(w_, h_)); } else { cv::resize(image, image_resized, cv::Size(w_, h_)); }
codeNV_CUDA_CHECK(cudaStreamCreate(&(stream_[imgNum]))); //transfer the image to GPU NV_CUDA_CHECK(cudaMemcpyAsync(inputGpu_, inputCpu_, h_ * w_ * 3 * sizeof(unsigned char), cudaMemcpyHostToDevice, stream_[imgNum])); //normalize image and reshape it such that it has channels-first format (required by neural net) NV_CUDA_CHECK(preprocessOnGpuWrapper(inputGpu_, inputCfGpu_, h_, w_, coef_, mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2])); //inference buffers_[0] = inputCfGpu_; buffers_[1] = outputRawGpu_; context_->getBindingDimensions(0); context_->enqueueV2((void **)buffers_, stream_[imgNum], nullptr); NV_CUDA_CHECK(cudaStreamSynchronize(stream_[imgNum])); NV_CUDA_CHECK(cudaDeviceSynchronize()); //compute segmentation masks from raw neural net ouput NV_CUDA_CHECK(computeOutputOnGpuWrapper(outputRawGpu_, outputMaskGpu_, h_, w_, numClasses_, threshold_)); //transfer result from GPU to the host NV_CUDA_CHECK(cudaMemcpy(outputMaskCpu_, outputMaskGpu_, h_ * w_ * sizeof(unsigned char), cudaMemcpyDeviceToHost)); // V1-2, 5 // Wait for the work in the stream to complete. // Release stream. NV_CUDA_CHECK(cudaStreamDestroy(stream_[imgNum])); //resize masks to the size of the input image cv::Mat masks(h_, w_, 0, outputMaskCpu_); if (up_crop_ != 0) { cv::Mat out, resize_mask; cv::Mat zero(up_crop_, image.cols, 0, 0.0); std::int16_t cropRows = image.rows - up_crop_; cv::resize(masks, resize_mask, cv::Size(image.cols, cropRows)); cv::vconcat(zero, resize_mask, out); cv::resize(out, masks, cv::Size(image.cols, image.rows), 0, 0, cv::INTER_NEAREST); cv::rectangle(image, cv::Rect(0, up_crop_, image.cols, cropRows), cv::Scalar(0, 0, 255), 1, 4, 0); } else { cv::resize(masks, masks, cv::Size(image.cols, image.rows), 0, 0, cv::INTER_NEAREST); } masksOut.emplace_back(std::move(masks)); imgNum++; } return masksOut; - Assistant
- User
cudaStream_t *stream_;
- Assistant
Thanks for clarifying that
stream_is declared as a raw pointer:cpp