How to cast OpenCV cv::Mat as NULL pointer?

which is ? can you point us to the API used here ?
why do you assume, a pointer to cv::Mat is expected on the “other side” ?
what about the memleak above ? who’s responsible to delete it ? pointer ownership ?
what are you trying to achieve here ?
(this seriously looks like an XY problem)

no, your code is not showing that

also, totally wrong here:

(trying to access a member on a NULL pointer)