int find_code(ColorImageFrame colorFrame, DepthImageFrame depthFrame) { ZXing.Kinect.BarcodeReader reader = new ZXing.Kinect.BarcodeReader(); if (colorFrame != null) { //Decode the colorFrame var result = reader.Decode(colorFrame); if (result != null) { string val = result.Text; int code_num = Convert.ToInt32(val); double center_x = result.ResultPoints[0].X + 0.5 * (result.ResultPoints[2].X - result.ResultPoints[0].X); double center_y = result.ResultPoints[0].Y + 0.5 * (result.ResultPoints[2].Y - result.ResultPoints[0].Y); code_size = new Point((result.ResultPoints[2].X - result.ResultPoints[0].X), (result.ResultPoints[2].Y - result.ResultPoints[0].Y)); // Must mirror the coordinate here -- the depth frame comes in mirrored. center_x = 640 - center_x; // Map the color frame onto the depth frame DepthImagePixel[] depthPixel = new DepthImagePixel[depthFrame.PixelDataLength]; depthFrame.CopyDepthImagePixelDataTo(depthPixel); DepthImagePoint[] depthImagePoints = new DepthImagePoint[sensor.DepthStream.FramePixelDataLength]; sensor.CoordinateMapper.MapColorFrameToDepthFrame(sensor.ColorStream.Format, sensor.DepthStream.Format, depthPixel, depthImagePoints); // Get the point in the depth frame at the center of the barcode int center_point_color_index = (int)center_y * 640 + (int)center_x; DepthImagePoint converted_depth_point = depthImagePoints[center_point_color_index]; Point p = new Point(converted_depth_point.X, converted_depth_point.Y); code_points[code_num] = p; Console.WriteLine("Found code " + code_num + " at (" + center_x + ", " + center_y + ") in color coordinates."); Console.WriteLine("Translated to (" + p.X + ", " + p.Y + ") in depth coordinates."); return(code_num); } } return(-1); }
int find_code(ColorImageFrame colorFrame, DepthImageFrame depthFrame) { ZXing.Kinect.BarcodeReader reader = new ZXing.Kinect.BarcodeReader(); if (colorFrame != null) { //Decode the colorFrame var result = reader.Decode(colorFrame); if (result != null) { string val = result.Text; int code_num = Convert.ToInt32(val); double center_x = result.ResultPoints[0].X + 0.5 * (result.ResultPoints[2].X - result.ResultPoints[0].X); double center_y = result.ResultPoints[0].Y + 0.5 * (result.ResultPoints[2].Y - result.ResultPoints[0].Y); code_size = new Point((result.ResultPoints[2].X - result.ResultPoints[0].X), (result.ResultPoints[2].Y - result.ResultPoints[0].Y)); // Must mirror the coordinate here -- the depth frame comes in mirrored. center_x = 640 - center_x; // Map the color frame onto the depth frame DepthImagePixel[] depthPixel = new DepthImagePixel[depthFrame.PixelDataLength]; depthFrame.CopyDepthImagePixelDataTo(depthPixel); DepthImagePoint[] depthImagePoints = new DepthImagePoint[sensor.DepthStream.FramePixelDataLength]; sensor.CoordinateMapper.MapColorFrameToDepthFrame(sensor.ColorStream.Format, sensor.DepthStream.Format, depthPixel, depthImagePoints); // Get the point in the depth frame at the center of the barcode int center_point_color_index = (int)center_y * 640 + (int)center_x; DepthImagePoint converted_depth_point = depthImagePoints[center_point_color_index]; Point p = new Point(converted_depth_point.X, converted_depth_point.Y); code_points[code_num] = p; Console.WriteLine("Found code " + code_num + " at (" + center_x + ", " + center_y + ") in color coordinates."); Console.WriteLine("Translated to (" + p.X + ", " + p.Y + ") in depth coordinates."); return code_num; } } return -1; }