I am using the below snippet of code to convert Planar FP16 BGR data to cv::mat for display using imshow. I have verified that the type (planar16bgr) and size (416x416) are correct. However the image does not display correctly and appears to be even varying over time - though scene is static. I am lost on what I am doing wrong - any inputs are appreciated.
Example images


BGR values at certain pixels (100,100) and (415,415) in consecutive frames

Code Snippet
auto inRgb = ptQ->get<dai::ImgFrame>(); // Get Image Frame
auto img_type=inRgb->getType(); // Verified it evaluates to 27 - which is Planar FP16 BGR data
auto mat_in = inRgb->getData(); //Using getData(). getCvFrame() failed, complains about not having built with OpenCV
cv::Size size = cv::Size(inRgb->getWidth(), inRgb->getHeight());
cv::Mat mat = cv::Mat(size, CV_8UC3);
std::cout << "Width: " << size.width << std::endl; // Verified to be 416
std::cout << "Height: " << size.height << std::endl; // Verified to be 416
std::cout << "Size: " << mat_in.size() << std::endl; // Verified to be 1038336 = 416*416*3*2
int off1=(415 * 416 + 415)*2+2; //offset to second plane
int off2=(415 * 416 + 415)*4+4; //offset to third plane
for (int x = 0; x < 416; ++x) {
for (int y = 0; y < 416; ++y) {
int idx=(x * 416 + y)*2;
const uint16_t* fp16_b = (const uint16_t*) (mat_in.data() + idx);
uint8_t b = (uint8_t) (fp16_ieee_to_fp32_value(fp16_b[0]) * 255.0f);
const uint16_t* fp16_g = (const uint16_t*) (mat_in.data() + idx + off1);
uint8_t g = (uint8_t) (fp16_ieee_to_fp32_value(fp16_g[0]) * 255.0f);
const uint16_t* fp16_r = (const uint16_t*) (mat_in.data() + idx + off2);
uint8_t r = (uint8_t) (fp16_ieee_to_fp32_value(fp16_r[0]) * 255.0f);
mat.at<cv::Vec3b>(x, y) = cv::Vec3b(b,g,r);
}
}
cv::imshow("image", mat);
cv::waitKey(10);