В настоящее время я пытаюсь объединить два отдельных изображения с камеры в одно изображение как анаглиф. Результат должен выглядеть примерно так, как здесь.
Вот мой код, который я написал для захвата двух изображений камеры и преобразования их в черно-белое:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.Util;
namespace CameraStereoCapture {
public partial class CameraStereoCapture : Form {
private bool captureInProgress;
private VideoCapture cameraLeft = null;
private VideoCapture cameraRight = null;
private Mat leftRawFrame;
private Mat rightRawFrame;
private Mat leftGrayFrame;
private Mat rightGrayFrame;
private Mat stereoFrame;
public CameraStereoCapture() {
InitializeComponent();
CvInvoke.UseOpenCL = false;
try {
cameraLeft = new VideoCapture(1);
cameraLeft.ImageGrabbed += ProcessFrame;
cameraRight = new VideoCapture(0);
cameraRight.ImageGrabbed += ProcessFrame;
} catch (NullReferenceException ex) {
MessageBox.Show(ex.Message);
}
leftRawFrame = new Mat();
rightRawFrame = new Mat();
leftGrayFrame = new Mat();
rightGrayFrame = new Mat();
stereoFrame = new Mat();
}
private void cmdCapture_Click(object sender, EventArgs e) {
if (cameraLeft != null) {
if (captureInProgress) {
// stop the capture
cmdCapture.Text = "Start Capture";
cameraLeft.Pause();
cameraRight.Pause();
} else {
// start the capture
cmdCapture.Text = "Stop Capture";
cameraLeft.Start();
cameraRight.Start();
}
captureInProgress = !captureInProgress;
}
}
private void ProcessFrame(object sender, EventArgs arg) {
// capture and cache image from left camera
if (cameraLeft != null && cameraLeft.Ptr != IntPtr.Zero) {
cameraLeft.Retrieve(leftRawFrame, 0);
imgLeft.Image = leftRawFrame;
}
// capture and cache image from right camera
if (cameraRight != null && cameraRight.Ptr != IntPtr.Zero) {
cameraRight.Retrieve(rightRawFrame, 0);
imgRight.Image = rightRawFrame;
}
// calculate stereo image by combining the left and right image
if (leftRawFrame != null && rightRawFrame!=null) {
CvInvoke.CvtColor(leftRawFrame, leftGrayFrame, ColorConversion.Bgr2Gray);
CvInvoke.CvtColor(rightRawFrame, rightGrayFrame, ColorConversion.Bgr2Gray);
// TODO: how to convert 'leftRawImage to Cyan' ???
// TODO: how to convert 'rightRawImage to Magenta' ???
CvInvoke.AddWeighted(leftGrayFrame, 0.5, rightGrayFrame, 0.5, 1.0, stereoFrame);
imgStereo.Image = stereoFrame;
}
}
}
}
У меня вопрос: как преобразовать серые изображения в Cyan
и Magenta
или Red
и Blue
(стр. Строки в фрагменте кода, помеченные как TODO:
)?