opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

RICInterpolator error: error appeares when using the gray image as input

Open Jia-Baos opened this issue 2 years ago • 1 comments

RICInterpolator error: error appeares when using the gray image as input

System information (version)
  • OpenCV = 4.6.0
  • Operating System / Platform = Windows 64 Bit
  • Compiler = Visual Studio 2022
Detailed description

-- i have got the sparse flow, so that i want to use RICInterpolator get dense flow, but error will appear when using the gray image as input.

this is the information about error: OpenCV(4.6.0) Error: Unspecified error (> Invalid number of channels in input image:

'VScn::contains(scn)'

where 'scn' is 1 ) in __cdecl cv::impl::anonymous-namespace'::CvtHelper<struct cv::impl::anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xaa112eac::Set<3,-1,-1>,struct cv::impl::A0xaa112eac::Set<0,5,-1>,2>::CvtHelper(const class cv::debug_build_guard::_InputArray &,const class cv::debug_build_guard::_OutputArray &,int), file D:\opencv_contrib\opencv-4.6.0\modules\imgproc\src\color.simd_helpers.hpp, line 92 OpenCV: terminate handler is called! The last OpenCV error is: OpenCV(4.6.0) Error: Unspecified error (> Invalid number of channels in input image: 'VScn::contains(scn)' where 'scn' is 1 ) in __cdecl cv::impl::anonymous-namespace'::CvtHelper<struct cv::impl::anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xaa112eac::Set<3,-1,-1>,struct cv::impl::A0xaa112eac::Set<0,5,-1>,2>::CvtHelper(const class cv::debug_build_guard::_InputArray &,const class cv::debug_build_guard::_OutputArray &,int), file D:\opencv_contrib\opencv-4.6.0\modules\imgproc\src\color.simd_helpers.hpp, line 92

Steps to reproduce
#include <iostream>
#include <string>
#include <chrono>
#include <opencv2/ximgproc/sparse_match_interpolator.hpp>
#include "CPM.h"

int main(int argc, char* argv[])
{
	std::string I1_path = "D:\\Code-VS\\Project-CPM\\Project-CPM\\picutre\\MPI-Sintel\\frame_0001.png";
	std::string I2_path = "D:\\Code-VS\\Project-CPM\\Project-CPM\\picutre\\MPI-Sintel\\frame_0002.png";

	// the image should enjoy the same size
	cv::Mat I1 = cv::imread(I1_path);
	cv::Mat I2 = cv::imread(I2_path);
	cv::cvtColor(I1, I1, cv::COLOR_BGR2GRAY);
	cv::cvtColor(I2, I2, cv::COLOR_BGR2GRAY);
	ImagePadded(I1, I2);
	const int w = I1.cols;
	const int h = I1.rows;
	std::vector<cv::Point2f> matches_1;
	std::vector<cv::Point2f> matches_2;

	const auto t1 = std::chrono::system_clock::now();
	CPM* cpm = new CPM();
	cpm->Matching(I1, I2, matches_1, matches_2);
	delete cpm;
	const auto t2 = std::chrono::system_clock::now();
	const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
	std::cout << "CPM computation time: " << duration << " [msec]" << std::endl;

	/*cv::Mat I2_revised;
	cv::Mat sparse_flow;
	SaveOpticalFlow(sparse_flow, matches_1, matches_2, w, h, 2);
	MovePixels(I2, I2_revised, sparse_flow, cv::INTER_CUBIC);
	cv::namedWindow("res", cv::WINDOW_NORMAL);
	cv::imshow("res", abs(I2_revised - I1));

	cv::Mat draw;
	DrawOpticalFlow(draw, matches_1, matches_2, w, h, 2);
	cv::namedWindow("draw", cv::WINDOW_NORMAL);
	cv::imshow("draw", draw);*/

	cv::Mat I2_revised;
	cv::Mat dense_flow, dense_flow_show;
	cv::Ptr<cv::ximgproc::EdgeAwareInterpolator> pDollar = cv::ximgproc::createEdgeAwareInterpolator();
	//cv::Ptr<cv::ximgproc::RICInterpolator> pDollar = cv::ximgproc::createRICInterpolator();
	pDollar->interpolate(I1, matches_1, I2, matches_2, dense_flow);
	MovePixels(I2, I2_revised, dense_flow, cv::INTER_CUBIC);
	OpticalFlowShow(dense_flow, dense_flow_show);

	cv::namedWindow("dense_flow", cv::WINDOW_NORMAL);
	cv::imshow("dense_flow", dense_flow_show);
	cv::namedWindow("res", cv::WINDOW_NORMAL);
	cv::imshow("res", abs(I2_revised - I1));
	cv::imwrite("dense_flow_EpicFlow.png", dense_flow_show);
	cv::imwrite("res_EpicFlow.png", abs(I2_revised - I1));

	cv::waitKey();
	return 0;
}
Issue submission checklist
  • [ ] I report the issue, it's not a question
  • [ ] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • [ ] I updated to the latest OpenCV version and the issue is still there
  • [ ] There is reproducer code and related data files: videos, images, onnx, etc

Jia-Baos avatar Feb 23 '23 15:02 Jia-Baos

/cc @tsenst (author of https://github.com/opencv/opencv_contrib/pull/2367)

alalek avatar Feb 23 '23 23:02 alalek