Как декодировать определенную область в изображении с помощью ручного выбора? - PullRequest
0 голосов
/ 11 июля 2019

У меня есть изображение с несколькими штрих-кодами внутри графического блока.

Я понятия не имею, как выбрать конкретную область штрих-кода и декодировать ее.

Я выполнил функцию подсветки, но после подсветки штрих-кода появится сообщение об ошибке типа «Прямоугольник кадрирования больше, чем входное изображение».Я застрял в эти несколько дней и не знаю, как это сделать.

private Rectangle Rect = new Rectangle();
private Brush selectionBrush = new SolidBrush(Color.FromArgb(128, 72, 145, 220));

private void IronBarcode()
{
      if (pcbox.Image != null)
      {
      BarcodeResult[] ImageResults=BarcodeReader.ReadAllBarcodes("barcode.jpg", 
      BarcodeEncoding.All,BarcodeReader.BarcodeRotationCorrection.Low, 
      BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
      }
       foreach (var PageResult in ImageResults)
       {
        string Value = PageResult.Value;
         BarcodeEncoding BarcodeType = PageResult.BarcodeType;

         decoded += "Decode: " + PageResult.Value + Type: " + BarcodeType";    
        }
     if (decoded != "")
     {
      txtoutput.Text = decoded;
     }
}


private void pcbox_Paint(object sender, PaintEventArgs e)
{
// Draw the rectangle...
  if (pcbox.Image != null)
  {
     if (Rect != null && Rect.Width > 0 && Rect.Height > 0)
     {
       e.Graphics.FillRectangle(selectionBrush, Rect);
     }
  }
}
private void pcbox_MouseDown(object sender, MouseEventArgs e)
{
  // Determine the initial rectangle coordinates...
  RectStartPoint = e.Location;
  Invalidate();
}

private void pcbox_MouseMove(object sender, MouseEventArgs e)
{
  if (e.Button != MouseButtons.Left)
  return;
   Point tempEndPoint = e.Location;
   Rect.Location = new Point(
   Math.Min(RectStartPoint.X, tempEndPoint.X),
   Math.Min(RectStartPoint.Y, tempEndPoint.Y));
   Rect.Size = new Size(
   Math.Abs(RectStartPoint.X - tempEndPoint.X),
   Math.Abs(RectStartPoint.Y - tempEndPoint.Y));
   pcbox.Invalidate();
}

private void pcbox_MouseUp(object sender, MouseEventArgs e)
{
  if (e.Button == MouseButtons.Right)
  if (Rect.Contains(e.Location))
  {
     BarcodeResult[] InvoiceResults = 
     BarcodeReader.ReadAllBarcodesInCropArea("barcode.jpg",Rect, 
     BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, 
     BarcodeReader.BarcodeImageCorrection.None);

        foreach (var rs in InvoiceResults)
        {
          txtoutput.Text = r s.Text;
        }

   }
}

Я хочу декодировать только тот штрих-код, который я выбрал. enter image description here

...