Reputation: 1475
I'm trying to select a pixel color of the frames of my webcam. So I capture the frames an show then in a ImageBox without any problem. But when I try to access the image stored on ImageBox when I double click on the ImageBox I get a CvException. The exception pop when I try to get the pixel of the image.
OpenCV: unrecognized or unsupported array type
This is how I capture the frames:
// On Form Load
Application.Idle += ProcessFrame;
private void ProcessFrame(object sender, EventArgs arg)
{
if (cap != null)
{
using (Image<Bgr, byte> frame = cap.QueryFrame())
{
if (frame != null)
{
imageFrame = frame;
imageBoxFrame.Image = imageFrame;
Bgr color = imageFrame[50, 100];
}
}
}
}
And in DoubleClick Event:
private void imageBoxFrame_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (treeViewObjects.SelectedNode is ColorNode && !isTracking)
{
if (imageFrame == null)
return;
Emgu.CV.UI.ImageBox imageBox = (Emgu.CV.UI.ImageBox)sender;
Image<Bgr, byte> image = (Image<Bgr, byte>)imageBox.Image;
Bgr color = image[e.X, e.Y]; // This line causes the Exception
}
}
Apparently the image is not null. What I doing wrong? Maybe something with thread things?
Upvotes: 2
Views: 7554
Reputation: 5893
(Question answered by the OP and Answer posting requested. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
I solved it.
I just need to Clone the image because the using statement erase image data. So, on ProcessEvent I just need to clone the frame to imageFrame.
imageFrame = frame.Clone();
And have another problem. The correct way to access the pixel data is by [Y,X] not [X,Y].
Bgr color = image[e.Y, e.X];
Upvotes: 3