private void videoNewFrame(object sender, NewFrameEventArgs args) { Bitmap temp = args.Frame.Clone() as Bitmap; try { frameCounter++; if (frameCounter > 10) { cards = recognizer.Recognize(temp); frameCounter = 0; } //Draw Rectangle around cards and write card strings on card using (Graphics graph = Graphics.FromImage(temp)) { foreach (Card card in cards) { graph.DrawPolygon(pen, card.Corners); //Draw a polygon around card PointF point = CardRecognizer.GetStringPoint(card.Corners); //Find Top left corner point.Y += 10; graph.DrawString(card.ToString(), font, Brushes.White, point); //Write string on card } } } catch { } this.pictureBox1.Image = ResizeBitmap(temp); }
public IHttpActionResult UploadImage() { var fileUploaded = false; CardCollection returnData = null; foreach (string upload in HttpContext.Current.Request.Files) { if (!HasFile(HttpContext.Current.Request.Files[upload])) { continue; } string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "uploads"); string filename = Path.GetFileName(HttpContext.Current.Request.Files[upload].FileName); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } HttpContext.Current.Request.Files[upload].SaveAs(Path.Combine(path, filename)); fileUploaded = true; Image savedImage = Image.FromFile(path + @"\" + filename); Bitmap bitmap = new Bitmap(savedImage); returnData = recognizer.Recognize(bitmap); savedImage = null; } if (fileUploaded) { if (returnData != null && returnData.Count > 0) { return(Json(returnData[0].ToString())); } else { return(Json("No cards")); } } else { return(Json("Error")); } }
private void ProcessRecognition() { for (int i = 0; i <= 2; i++) { if (counter3 == 0) { this.image = im1; } else if (counter3 == 1) { this.image = im2; } else { this.image = im3; } CardCollection cards = recognizer.Recognize(this.image); //cardImagePanel.DrawImages(cards.ToImageList()); String r, b; //txtCards.Clear(); //foreach (Card card in cards) //{ //txtCards.AppendText(card.ToString() + Environment.NewLine); getScore(); //getWinner(); //} // */ //Draw Rectangle around cards and write card strings on card using (Graphics graph = Graphics.FromImage(image)) { foreach (Card card in cards) { graph.DrawPolygon(pen, card.Corners); //Draw a polygon around card PointF point = CardRecognizer.GetStringPoint(card.Corners); //Find Top left corner point.Y += 10; graph.DrawString(card.ToString(), font, Brushes.White, point); //Write string on card } } /* * r = recognizer.rank1.ToString(); * b = recognizer.numBlack.ToString(); * txtRed.Text = r; * txtBlack.Text = b; */ /* * recognizer.numRed = 0; * recognizer.numBlack = 0; */ if (counter3 == 0) { pb1.Image = ResizeBitmap(this.image); } else if (counter3 == 1) { pb2.Image = ResizeBitmap(this.image); } else { pb3.Image = ResizeBitmap(this.image); } //this.pb_loaded.Image = ResizeBitmap(this.image); counter3++; } getWinner(); }