Hi All,
i have modified ElastixTranslationExample.cxx example by adding open cv api to read the moving and fixed image and below is my sample code. exceptions is getting thrown at line highlighted in red below:
exception:Exception thrown at 0x00007FF606726D2D in elastix_translation_example.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
Please advice and assist me in resolving this error.
#include <itkElastixRegistrationMethod.h>
#include <elxParameterObject.h>
#include <Core/elxVersionMacros.h>
#include <iostream>
#include <itkImage.h>
#include "itkImageFileReader.h"
#include "itkOpenCVImageBridge.h"
#include <itkSize.h>
#include <cassert>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/opencv.hpp"
#include "param.h"
using namespace std;
int main()
{
enum
{
imageSizeX = 6,
imageSizeY = 5
};
typedef itk::Image<unsigned char, 2> ImageType;
cout << "Built with OpenCV 0" << CV_VERSION << endl;
cv::Mat sem_input= cv::imread("C:/Users/e182000/Documents/cad2semm/waveform/B79Y22ADD/wf9_Meas.tif");
cv::Mat cad_input = cv::imread("C:/Users/e182000/Documents/cad2semm/waveform/B79Y22ADD/wf9_Model.tif");
ImageType::Pointer itkFixedImage = ImageType::New();
ImageType::Pointer itkMovingImage = ImageType::New();
CADBasedCoarseEdgeRecipeParams *recipe_params = new CADBasedCoarseEdgeRecipeParams();
recipe_params->setMaxNumOfIerationsFactor(0.1);
cout << "Built with OpenCV 1-> " << CV_VERSION << endl;
itkFixedImage = itk::OpenCVImageBridge::CVMatToITKImage< ImageType >(sem_input);
cout << "Built with OpenCV 2-> " << CV_VERSION << endl;
itkMovingImage = itk::OpenCVImageBridge::CVMatToITKImage< ImageType >(cad_input);
cout << "Built with OpenCV 3->" << CV_VERSION << endl;
cv::imshow("Sample", sem_input);
cv::waitKey(0);
cv::Mat image_blurred_with_3x3_kernel;
cv::GaussianBlur(sem_input, image_blurred_with_3x3_kernel, cv::Size(3, 3), 0);
cv::imshow("Blurred", image_blurred_with_3x3_kernel);
cv::waitKey(0);
const auto parameterObject = elx::ParameterObject::New();
parameterObject->SetParameterMap(
elx::ParameterObject::ParameterMapType{ { "ImageSampler", { "Full" } },
{ "MaximumNumberOfIterations", { "44" } },
{ "Metric", { "AdvancedNormalizedCorrelation" } },
{ "Optimizer", { "AdaptiveStochasticGradientDescent" } },
{ "Transform", { "TranslationTransform" } } });
const auto filter = itk::ElastixRegistrationMethod<ImageType, ImageType>::New();
filter->SetFixedImage(itkFixedImage);
filter->SetMovingImage(itkMovingImage);
filter->SetParameterObject(parameterObject);
filter->Update();
// filter->UpdateLargestPossibleRegion();
} // end main()
Regards
Kunal