I am using AForge.Net framework to do some video processing.
What I am doing is:
1 - Browse Video File(.AVI format) or Connect to Video Capture Device
2 - Display the original video in picturebox1
3 - manipulate the video into black and white and display in picturebox2
4 - count zero and one from manipulated video and display sum in textbox1
So far I have done the 1st until 3rd steps
I am now stuck on the 4th step
What I understand:
i - get img from video and store them in a variable
ii - loop to check every pixel color from stored img
iii- display into textbox
Here is the code, it worked when I tested them on a picture. but failed when testing on a video.
private void binaryImg(Bitmap bimg, int x , int y)
{
for (int i = 0; i < bimg.Height; i++)
{
for (int j = 0; j < bimg.Width; j++)
{
if (bimg.GetPixel(j,i).B.ToString() == "255" && bimg.GetPixel(j,i).G.ToString() == "255" && bimg.GetPixel(j,i).R.ToString() == "255")
x += 1;
else
y += 1;
}
textBox1.Text = "ONE: " + x + "\n\rTWO: " + y;
}
}
The bimg was the black/white video stream..I used the edgedetector from AForge.Net
private void displayFrame(object sender, NewFrameEventArgs eventArgs)
{
picturebox1.Image = (Bitmap)eventArgs.Frame.Clone(); // original video
Bitmap image = (Bitmap)eventArgs.Frame.Clone();
Bitmap greyImg = Grayscale.CommonAlgorithms.BT709.Apply(image);
SobelEdgeDetector filter = new SobelEdgeDetector();
Bitmap edge = filter.Apply(greyImg);
picturebox2.Image = (Bitmap)egde; //black/white video
binaryImg(edge,one,zero);
textBox1.Text = "ONE: " + one + "\n\rTWO : " + zero;//}
}
The binaryImage took some time when I tested them to process a big picture, so how can I fix this?
What did I do wrong?
I also got an InvalidOperationException "Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on."
when I tried to use them on a video file/webcam.
Thank you.

New Topic/Question
Reply




MultiQuote




|