Hi
This error looks like invalid cv::Mat image, such as invalid width/height.
I modify your code into ‘VisionWorks-1.5-Samples/samples/opencv_npp_interop/main_opencv_npp_interop.cpp’ sample.
This sample can compile and run normally, for your reference.
/*
# Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <iostream>
#include "NVXIO/Application.hpp"
#include "NVX/nvx_opencv_interop.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#if !defined USE_OPENCV || !defined USE_NPP
int main(int, char**)
{
#ifndef USE_OPENCV
std::cout << "NVXIO and samples were built without OpenCV support." << std::endl;
std::cout << "Install OpenCV for Tegra and rebuild the sample." << std::endl;
#endif
#ifndef USE_NPP
std::cout << "The sample was built without CUDA NPP support." << std::endl;
std::cout << "Install CUDA NPP library and rebuild the sample." << std::endl;
#endif
return nvxio::Application::APP_EXIT_CODE_ERROR;
}
#else
#include <string>
#include <iomanip>
#include <memory>
#include <NVX/nvx.h>
#include <NVX/nvx_timer.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "alpha_comp_node.hpp"
#include "NVXIO/Render.hpp"
#include "NVXIO/SyncTimer.hpp"
#include "NVXIO/Utility.hpp"
struct EventData
{
EventData(): shouldStop(false), pause(false) {}
bool shouldStop;
bool pause;
};
static void eventCallback(void* eventData, vx_char key, vx_uint32, vx_uint32)
{
EventData* data = static_cast<EventData*>(eventData);
if (key == 27)
{
data->shouldStop = true;
}
else if (key == 32)
{
data->pause = !data->pause;
}
}
static void displayState(nvxio::Render *renderer, const cv::Size & size, double proc_ms, double total_ms)
{
std::ostringstream txt;
txt << std::fixed << std::setprecision(1);
txt << "Source size: " << size.width << 'x' << size.height << std::endl;
txt << "Algorithm: " << proc_ms << " ms / " << 1000.0 / proc_ms << " FPS" << std::endl;
txt << "Display: " << total_ms << " ms / " << 1000.0 / total_ms << " FPS" << std::endl;
txt << std::setprecision(6);
txt.unsetf(std::ios_base::floatfield);
txt << "LIMITED TO " << nvxio::Application::get().getFPSLimit() << " FPS FOR DISPLAY" << std::endl;
txt << "Space - pause/resume" << std::endl;
txt << "Esc - close the demo";
nvxio::Render::TextBoxStyle style = {{255, 255, 255, 255}, {0, 0, 0, 127}, {10, 10}};
renderer->putTextViewport(txt.str(), style);
}
static void VX_CALLBACK myLogCallback(vx_context /*context*/, vx_reference /*ref*/, vx_status /*status*/, const vx_char string[])
{
std::cout << "VisionWorks LOG : " << string << std::endl;
}
//
// main - Application entry point
//
int main(int argc, char* argv[])
{
try
{
nvxio::Application &app = nvxio::Application::get();
//
// Parse command line arguments
//
std::string fileName1 = app.findSampleFilePath("lena.jpg");
std::string fileName2 = app.findSampleFilePath("baboon.jpg");
app.setDescription("This sample accepts as input two images and performs alpha blending of them");
app.addOption(0, "img1", "First image", nvxio::OptionHandler::string(&fileName1));
app.addOption(0, "img2", "Second image", nvxio::OptionHandler::string(&fileName2));
app.init(argc, argv);
//
// Load input images
//
if (fileName1 == fileName2)
{
std::cerr << "Error: Please, use different files for img1 and img2" << std::endl;
return nvxio::Application::APP_EXIT_CODE_INVALID_VALUE;
}
cv::Mat cv_src1 = cv::imread(fileName1, cv::IMREAD_GRAYSCALE);
cv::Mat cv_src2 = cv::imread(fileName2, cv::IMREAD_GRAYSCALE);
if (cv_src1.empty())
{
std::cerr << "Error: Can't load input image " << fileName1 << std::endl;
return nvxio::Application::APP_EXIT_CODE_NO_RESOURCE;
}
if (cv_src2.empty())
{
std::cerr << "Error: Can't load input image " << fileName2 << std::endl;
return nvxio::Application::APP_EXIT_CODE_NO_RESOURCE;
}
if (cv_src1.size() != cv_src2.size())
{
std::cerr << "Error: Input images must have the same size." << std::endl;
return nvxio::Application::APP_EXIT_CODE_INVALID_DIMENSIONS;
}
//
// Create OpenVX context
//
nvxio::ContextGuard context;
vxRegisterLogCallback(context, &myLogCallback, vx_false_e);
vxDirective(context, VX_DIRECTIVE_ENABLE_PERFORMANCE);
std::unique_ptr<nvxio::Render> renderer(nvxio::createDefaultRender(context, "OpenCV NPP Interop Sample",
3 * cv_src1.cols, cv_src1.rows));
if (!renderer) {
std::cerr << "Error: Can't create a renderer." << std::endl;
return nvxio::Application::APP_EXIT_CODE_NO_RENDER;
}
EventData eventData;
renderer->setOnKeyboardEventCallback(eventCallback, &eventData);
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// your code start from here
//
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
cv::Mat cv_left = cv_src1;
cv::Mat cv_right = cv_src2;
// please do some handle here
cv::cvtColor(cv_left, cv_left, cv::COLOR_RGB2GRAY);
cv::cvtColor(cv_right,cv_right, cv::COLOR_RGB2GRAY);
cv::Mat cv_left_dst(cv_left.size(), cv_left.type());
cv::Mat cv_right_dst(cv_right.size(), cv_right.type());
vx_image vx_src_left = nvx_cv::createVXImageFromCVMat(context, cv_left);
vx_image vx_dst_left = nvx_cv::createVXImageFromCVMat(context, cv_left_dst);
vx_image vx_src_right = nvx_cv::createVXImageFromCVMat(context, cv_right);
vx_image vx_dst_right = nvx_cv::createVXImageFromCVMat(context, cv_right_dst);
vxuBox3x3(context, vx_src_left, vx_dst_left);
vxuBox3x3(context, vx_src_right, vx_dst_right);
vxReleaseImage(&vx_src_left);
vxReleaseImage(&vx_dst_left);
vxReleaseImage(&vx_src_right);
vxReleaseImage(&vx_dst_right);
std::cout << "Failed 2";
//vx_image vx_left = createRGBImageFromRGBMat(context, cv_left);
//vx_image vx_right = createRGBImageFromRGBMat(context, cv_right);
std::cout << "Failed 1";
std::vector<cv::Mat> mat_images;
mat_images.push_back(cv_left_dst);
mat_images.push_back(cv_right_dst);
//
// Release all objects
//
renderer->close();
}
catch (const std::exception& e)
{
std::cerr << "Error: " << e.what() << std::endl;
return nvxio::Application::APP_EXIT_CODE_ERROR;
}
return nvxio::Application::APP_EXIT_CODE_SUCCESS;
}
#endif // USE_OPENCV
Thanks