Read Access Violation from opencv_cored.dll when using .converTo()

Hello!
I am a beginner and running into some trouble with the surface matching in opencv.
I am attempting to get depth from a depth camera and give it to a surface match. When I attempt to convert the Mat to CV_32F, which the detector.trainModel() needs, I get a Read Access Violation.

Exception thrown: read access violation.
ptr was 0x8A88000.

Mat imageD(Size(wD, hD), CV_8UC3, (void*)depth.get_data(), Mat::AUTO_STEP);

imageD.convertTo(imageD, CV_32F);

ppf_match_3d::PPF3DDetector detector(0.03, 0.05);
detector.trainModel(imageD);

imageD is the depth image I get from the camera.
wD is the width of the depth image.
hD is the height of the depth image.

Also, I am using Visual Studio 2019 with OpenCV version 4.3.0 through vcpkg.

Thanks for the help!

you’re gonna need to show more code. depth isn’t shown.

assuming, your input is CV_8UC3, you cannot convert it in-place to a single float channel (you would need to re-allocate the output) using that “borrowed pointer”.

convertTo also does not change the number of channels

probably the easiest solution is to use a new, empty Mat for the result:

Mat ImageG;
cvtColor(imageD, imageG, COLOR_BGR2GRAY);

Mat imageF;
imageG.convertTo(imageF, CV_32F);

ppf_match_3d::PPF3DDetector detector(0.03, 0.05);
detector.trainModel(imageF);

p.s.
i think, this is all the wrong approach. instead (lossy) conversion to float (what do you think, you gain here, even ?), you should find out, if it is possible to get a better image format from your cam directly