Unhandled exception in Unreal Engine 5.3

Unhandled exception at 0x00007FFE699FCB69 in UnrealEditor.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000007BC5D78630.

Hello,
I’m using the inbuilt opencv plugin (4.5) in UE 5.3.
My code reads an image , blurs it and try’s to save it to a folder.

Everything works up to reading the image and printing it’s dimensions but when i try and save the file I get the above exception thrown.

Here is my code in Unreal Engine

void Atest_blur::TestOpenCV()
{

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT(CV_VERSION));
	
	//cv::Mat webcam_image;
	cv::Mat img = cv::imread("D:/behram/UE5_dev/opencv_nick/UE5_opencv/test_blur_two/Data/adipurush.png", cv::IMREAD_COLOR); 

	if (img.empty())
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("img is empty"));
	}
	else
	{
		int image_width = img.rows;
		int image_height = img.cols;
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, FString::Printf(TEXT("dimensions width = %d,height = %d"), image_width, image_height));
        //FAILS 
        cv::imwrite("D:/behram/UE5_dev/opencv_nick/UE5_opencv/test_blur_two/Data/dest/blur_kernel.jpg", img);
	}

}

How would I debug something like this ?

Thanking you ,
b

catch the exception, print e.what()

1 Like

Thanks for that tip.

This is how my call stack looks in case it helps with whats going on.

I will try and catch the exception but I am not sure print works in Unreal Engine.

Thanks,
b

Hi I have an update.
I saved the image as a png instead of a jpg and the exception went away.

Im sure native opencv can save jpg files so the problem was with UE 5.3 ?
Once again, how would the call stack in UE help me finding out that jpg was causing the problem.

Thanks so much for any pointers.
b