private void timerGrab_Tick(object sender, EventArgs e)
{
frame = highgui.CvQueryFrame(ref videoCapture);
if (frame.ptr == IntPtr.Zero)
{
timerGrab.Stop();
MessageBox.Show("Invalid Frame");
return;
}
imgMain = cxcore.CvCreateImage(cxcore.CvGetSize(ref frame), 8, 3);
if (reset)
{
showROI = false;
initialized = false;
resetting();
}
cxcore.CvCopy(ref frame, ref imgMain);
cxcore.CvFlip(ref imgMain, 0);
#region ROI
if (showROI && initialized)
{
cxcore.CvRectangle(ref imgMain, new CvPoint(roiX, roiY), new CvPoint(roiX + roiW, roiY + roiH), cxcore.CV_RGB(255, 0, 125), 1, 8, 0);
imgCrop = cxcore.CvCreateImage(new CvSize(roiW, roiH), 8, 3);
#region skinHSV/RGB
if (showSkinHSV || showSkinRGB)
{
imgSkin = new IplImage();
imgSkin = cxcore.CvCreateImage(cxcore.CvGetSize(ref frame), 8, 3);
if (showSkinHSV)
{
imgSkin = skinDet.skin_hsv(imgMain);
}
else if (showSkinRGB)
{
imgSkin = skinDet.skin_rgb(imgMain);
}
cxcore.CvSetImageROI(ref imgSkin, new CvRect(roiX, roiY, roiW, roiH));
cxcore.CvCopy(ref imgSkin, ref imgCrop);
cxcore.CvReleaseImage(ref imgSkin);
//noise removal
cv.CvDilate(ref imgCrop, ref imgCrop, dlgParam.GetP(0).i);
cv.CvErode(ref imgCrop, ref imgCrop, dlgParam.GetP(1).i);
for (int i = 0; i < dlgParam.GetP(2).i; i++)
{
cv.CvSmooth(ref imgCrop, ref imgCrop);
}
}
#endregion
#region show threshold
if (showThres || showEdge)
{
imgGray = cxcore.CvCreateImage(cxcore.CvGetSize(ref imgCrop), 8, 1);
imgBin = cxcore.CvCreateImage(cxcore.CvGetSize(ref imgCrop), 8, 1);
imgMot = cxcore.CvCreateImage(cxcore.CvGetSize(ref imgCrop), 8, 1);
cv.CvCvtColor(ref imgCrop, ref imgGray, cvtypes.CV_BGR2GRAY);
cv.CvThreshold(ref imgGray, ref imgMot, 0, 255, cv.CV_THRESH_BINARY_INV);
abs.Absolute(imgMot);
if (showThres)
{
cv.CvThreshold(ref imgGray, ref imgBin, 0, 255, cv.CV_THRESH_BINARY_INV);
}
else if (showEdge)
{
edge_dlg();
cv.CvCanny(ref imgGray, ref imgBin, dlgCanny.GetP(0).i, dlgCanny.GetP(1).i);
}
highgui.CvShowImage("Crop", ref imgBin);
#region matching
if (match)
{
if (adaBlackPix(imgBin))
{
hasil = (int)KNN.classify(ref imgBin, false);
}
else
{
hasil = 19;
}
WriteLine(Signs[hasil], false, false);
match = false;
show_letter = true;
}
#endregion
cxcore.CvReleaseImage(ref imgGray);
cxcore.CvReleaseImage(ref imgCrop);
cxcore.CvReleaseImage(ref imgBin);
cxcore.CvReleaseImage(ref imgMot);
}
else
{
highgui.CvShowImage("Crop", ref imgCrop);
cxcore.CvReleaseImage(ref imgCrop);
}
#endregion
}
else if (!initialized && !showROI)
{
imgMain = hc.cariHaar(imgMain);
}
else if (!initialized) //initialize windows
{
initialize();
}
#endregion
if (show_letter)
{
CvFont font = new CvFont();
cxcore.CvInitFont(ref font, cxcore.CV_FONT_HERSHEY_SIMPLEX, 5, 5, 0, 10, cxcore.CV_AA);
cxcore.CvPutText(ref imgMain, Signs[hasil], new CvPoint(50, 200), ref font, new CvScalar(0, 255, 0));
}
picBoxMain.Image = highgui.ToBitmap(imgMain, false);
cxcore.CvReleaseImage(ref imgMain);
fps++;
if ((openx != 0 && openy != 0 && closex != 0 && closey != 0) && !showROI)
{
euclidean();
}
}