/// <summary> /// Process the image. /// </summary> /// <param name="matrix">Mat.</param> /// <param name="imageProcessingType">ImageProcessingType.</param> private void ProcessImage(Mat matrix, ImageProcessingType imageProcessingType = ImageProcessingType.None) { switch (imageProcessingType) { case ImageProcessingType.DrawLine: // Draw a diagonal line on our image Imgproc.line(matrix, new Point(0, 0), new Point(matrix.cols(), matrix.rows()), new Scalar(255, 0, 0, 255), 4); break; case ImageProcessingType.ConvertToGray: // Convert a four-channel mat image to greyscale if (grayMatrix != null && (grayMatrix.width() != matrix.width() || grayMatrix.height() != matrix.height())) { grayMatrix.Dispose(); grayMatrix = null; } grayMatrix = grayMatrix ?? new Mat(matrix.height(), matrix.width(), CvType.CV_8UC1); Imgproc.cvtColor(matrix, grayMatrix, Imgproc.COLOR_RGBA2GRAY); Imgproc.cvtColor(grayMatrix, matrix, Imgproc.COLOR_GRAY2RGBA); break; } }
/// <summary> /// Raises the image processing type dropdown value changed event. /// </summary> public void OnImageProcessingTypeDropdownValueChanged(int result) { if ((int)imageProcessingType != result) { imageProcessingType = (ImageProcessingType)result; } }
/// <summary> /// Process the image. /// </summary> /// <param name="buffer">Colors.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <param name="size">Size.</param> /// <param name="imageProcessingType">ImageProcessingType.</param> private void ProcessImage(Color32[] buffer, int width, int height, int size, ImageProcessingType imageProcessingType = ImageProcessingType.None) { switch (imageProcessingType) { case ImageProcessingType.DrawLine: // Draw a diagonal line on our image float inclination = height / (float)width; for (int i = 0; i < 4; i++) { for (int x = 0; x < width; x++) { int y = (int)(-inclination * x) + height - 2 + i; if (y < 0) { y = 0; } if (y > height - 1) { y = height - 1; } int p = (x) + (y * width); // Set pixels in the buffer buffer.SetValue(new Color32(255, 0, 0, 255), p); } } break; case ImageProcessingType.ConvertToGray: // Convert a four-channel pixel buffer to greyscale // Iterate over the buffer for (int i = 0; i < size; i++) { Color32 p = (Color32)buffer.GetValue(i); // Get channel intensities byte r = p.r, g = p.g, b = p.b, a = p.a, // Use quick luminance approximation to save time and memory l = (byte)((r + r + r + b + g + g + g + g) >> 3); // Set pixels in the buffer buffer.SetValue(new Color32(l, l, l, a), i); } break; } }
/// <summary> /// Process the image. /// </summary> /// <param name="buffer">Bytes.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <param name="size">Size.</param> /// <param name="imageProcessingType">ImageProcessingType.</param> private void ProcessImage(Byte[] buffer, int width, int height, int size, ImageProcessingType imageProcessingType = ImageProcessingType.None) { switch (imageProcessingType) { case ImageProcessingType.DrawLine: // Draw a diagonal line on our image float inclination = height / (float)width; for (int i = 0; i < 4; i++) { for (int x = 0; x < width; x++) { int y = (int)(-inclination * x) + height - 2 + i; if (y < 0) { y = 0; } if (y > height - 1) { y = height - 1; } int p = (x * 4) + (y * width * 4); // Set pixels in the buffer buffer[p] = 255; buffer[p + 1] = 0; buffer[p + 2] = 0; buffer[p + 3] = 255; } } break; case ImageProcessingType.ConvertToGray: // Convert a four-channel pixel buffer to greyscale // Iterate over the buffer for (int i = 0; i < size; i += 4) { // Get channel intensities byte r = buffer[i + 0], g = buffer[i + 1], b = buffer[i + 2], a = buffer[i + 3], // Use quick luminance approximation to save time and memory l = (byte)((r + r + r + b + g + g + g + g) >> 3); // Set pixels in the buffer buffer[i] = buffer[i + 1] = buffer[i + 2] = l; buffer[i + 3] = a; } break; } }
protected void ProcessImage(byte[] buffer, int width, int height, ImageProcessingType imageProcessingType) { switch (imageProcessingType) { case ImageProcessingType.DrawLine: // Draw a diagonal line on our image float inclination = height / (float)width; for (int i = 0; i < 4; i++) { for (int x = 0; x < width; x++) { int y = (int)(-inclination * x) + height - 2 + i; y = Mathf.Clamp(y, 0, height - 1); int p = (x * 4) + (y * width * 4); // Set pixels in the buffer buffer[p] = 255; buffer[p + 1] = 0; buffer[p + 2] = 0; buffer[p + 3] = 255; } } break; case ImageProcessingType.ConvertToGray: // Convert a four-channel pixel buffer to greyscale // Iterate over the buffer for (int i = 0; i < buffer.Length; i = i + 4) { // Get channel intensities byte r = buffer[i]; byte g = buffer[i + 1]; byte b = buffer[i + 2]; byte a = buffer[i + 3]; // Use quick luminance approximation to save time and memory byte l = (byte)((r + r + r + b + g + g + g + g) >> 3); // Set pixels in the buffer buffer[i] = buffer[i + 1] = buffer[i + 2] = l; buffer[i + 3] = a; } break; } }
protected void ProcessImage(Mat frameMatrix, Mat grayMatrix, ImageProcessingType imageProcessingType) { switch (imageProcessingType) { case ImageProcessingType.DrawLine: Imgproc.line( frameMatrix, new Point(0, 0), new Point(frameMatrix.cols(), frameMatrix.rows()), new Scalar(255, 0, 0, 255), 4 ); break; case ImageProcessingType.ConvertToGray: Imgproc.cvtColor(frameMatrix, grayMatrix, Imgproc.COLOR_RGBA2GRAY); Imgproc.cvtColor(grayMatrix, frameMatrix, Imgproc.COLOR_GRAY2RGBA); break; } }
protected void ProcessImage(Color32[] buffer, int width, int height, ImageProcessingType imageProcessingType) { switch (imageProcessingType) { case ImageProcessingType.DrawLine: // Draw a diagonal line on our image float inclination = height / (float)width; for (int i = 0; i < 4; i++) { for (int x = 0; x < width; x++) { int y = (int)(-inclination * x) + height - 2 + i; y = Mathf.Clamp(y, 0, height - 1); int p = (x) + (y * width); // Set pixels in the buffer buffer.SetValue(new Color32(255, 0, 0, 255), p); } } break; case ImageProcessingType.ConvertToGray: // Convert a four-channel pixel buffer to greyscale // Iterate over the buffer for (int i = 0; i < buffer.Length; i++) { var p = buffer[i]; // Get channel intensities byte r = p.r, g = p.g, b = p.b, a = p.a, // Use quick luminance approximation to save time and memory l = (byte)((r + r + r + b + g + g + g + g) >> 3); // Set pixels in the buffer buffer[i] = new Color32(l, l, l, a); } break; } }