/// <summary> /// show results /// </summary> /// <param name="left_bmp">left image data</param> /// <param name="image_width">width of the image</param> /// <param name="image_height">height of the image</param> /// <param name="output_bmp">image to be displayed</param> public virtual void Show(byte[] left_bmp, int image_width, int image_height, byte[] output_bmp) { if (left_bmp.Length == output_bmp.Length) { Buffer.BlockCopy(left_bmp, 0, output_bmp, 0, left_bmp.Length); } else { if (left_bmp.Length == output_bmp.Length / 3) { int n = 0; for (int i = 0; i < output_bmp.Length; i += 3, n++) { for (int col = 0; col < 3; col++) { output_bmp[i + col] = left_bmp[n]; } } } } for (int i = 0; i < features.Count; i++) { StereoFeature f = features[i]; drawing.drawSpotBlended(output_bmp, image_width, image_height, (int)f.x, (int)f.y, (int)(f.disparity * feature_scale), 100, 255, 100); } }
/// <summary> /// receive incoming stereo feature data and turn it into a list of stereo feature objects /// </summary> /// <param name="data">received data</param> /// <param name="no_of_bytes">received number of bytes</param> private void Receive(byte[] data, int no_of_bytes) { if ((data.Length > 1) && (!receive_busy)) { receive_busy = true; // create a list to store the features List <StereoFeature> new_features = new List <StereoFeature>(); // read the first byte, which determines whether // the stereo features have colour info or not if (data[0] == 1) { ColourFeatures = true; } else { ColourFeatures = false; } if (!ColourFeatures) { // stereo features with no colour information float[] feats = ReadData(data, no_of_bytes); for (int i = 0; i < feats.Length; i += 3) { StereoFeature f = new StereoFeature(feats[i], feats[i + 1], feats[i + 2]); new_features.Add(f); } } else { // stereo features with colour information float[] feats = null; byte[] colour = null; ReadDataColour(data, no_of_bytes, ref feats, ref colour); for (int i = 0; i < feats.Length; i += 3) { StereoFeature f = new StereoFeature(feats[i], feats[i + 1], feats[i + 2]); f.SetColour(colour[i], colour[i + 1], colour[i + 2]); new_features.Add(f); } } features = new_features; FeaturesArrived(features); receive_busy = false; } }
/// <summary> /// update the colours of stereo features /// </summary> /// <param name="left_img_colour">left colour image</param> /// <param name="right_img_colour">right colour image</param> private void UpdateFeatureColours(byte[] left_img_colour, byte[] right_img_colour) { for (int f = 0; f < features.Count; f++) { StereoFeature feature = features[f]; int n = (((int)feature.y * image_width) + (int)feature.x) * 3; feature.colour = new byte[3]; for (int col = 0; col < 3; col++) { feature.colour[col] = left_img_colour[n + col]; } } }
/// <summary> /// receive incoming stereo feature data and turn it into a list of stereo feature objects /// </summary> /// <param name="data">received data</param> /// <param name="no_of_bytes">received number of bytes</param> private void Receive(byte[] data, int no_of_bytes) { if ((data.Length > 1) && (!receive_busy)) { receive_busy = true; // create a list to store the features List<StereoFeature> new_features = new List<StereoFeature>(); // read the first byte, which determines whether // the stereo features have colour info or not if (data[0] == 1) ColourFeatures = true; else ColourFeatures = false; if (!ColourFeatures) { // stereo features with no colour information float[] feats = ReadData(data, no_of_bytes); for (int i = 0; i < feats.Length; i += 3) { StereoFeature f = new StereoFeature(feats[i], feats[i + 1], feats[i + 2]); new_features.Add(f); } } else { // stereo features with colour information float[] feats = null; byte[] colour = null; ReadDataColour(data, no_of_bytes, ref feats, ref colour); for (int i = 0; i < feats.Length; i += 3) { StereoFeature f = new StereoFeature(feats[i], feats[i + 1], feats[i + 2]); f.SetColour(colour[i], colour[i + 1], colour[i + 2]); new_features.Add(f); } } features = new_features; FeaturesArrived(features); receive_busy = false; } }