-1

I wrote some code for finding text from a camera. Actually I first wrote code for finding text in an image and I succeeded but I cant find text from the camera. Thank you in advance. In addition I wrote this code in classlibrary so I can't test it well.

public string GetImageText(string imgPath)
    {


        pathImage = imgPath;

        //CvCapture cap = new CvCapture(0);
       CvCapture cap;
       //CvCapture cap = new CvCapture(imgPath);
       cap = CvCapture.FromFile(imgPath);

       cap= CvCapture.FromCamera(CaptureDevice.Any);

      //  img = new IplImage(imgPath, LoadMode.Color);
      // cap =CvCapture.FromFile(imgPath);

      // IplImage frame = new IplImage();
       // imgPath=cap.QueryFrame(frame);
        frame = cap.QueryFrame();
       // IplImage frame = new IplImage();
       // BitmapConverter.ToBitmap(frame);
      //frame = new IplImage(imgPath, LoadMode.Color);


        if (frame != null)
        {
            IplImage img1 = new IplImage(frame.Size, BitDepth.U8, 1);
            IplConvKernel element = Cv.CreateStructuringElementEx(21, 3, 10, 2, ElementShape.Rect, null);
            aimg = new IplImage(frame.Size, BitDepth.U8, 1);
            IplImage temp = aimg.Clone();
            IplImage dest = aimg.Clone();
            frame.CvtColor(aimg, ColorConversion.RgbaToGray);
            bimg = aimg.Clone();
            Cv.Smooth(aimg, aimg, SmoothType.Gaussian);
            Cv.MorphologyEx(aimg, temp, dest, element, MorphologyOperation.TopHat, 1);

            Cv.Threshold(dest, aimg, 128, 255, ThresholdType.Binary | ThresholdType.Otsu);
            Cv.Smooth(aimg, dest, SmoothType.Median);
            Cv.Dilate(dest, dest, element, 2);

            Cv.ReleaseImage(temp);
            Cv.ReleaseImage(dest);
            IplImage labelImage = new IplImage(frame.Size, CvBlobLib.DepthLabel, 1);
            labelImage = new IplImage(frame.Size, BitDepth.U8, 1);
            frame = new IplImage(frame.Size, BitDepth.U8, 1);

            blob = new CvBlobs();
            text.Clear();
            CvBlobLib.Label(labelImage, blob);

            CvBlobLib.FilterByArea(blob, 6, 10);
            IplImage imgtemp = frame.Clone();
            foreach (var item in blob)
            {

                item.Value.SetImageRoiToBlob(bimg);

                double ratio = (double)item.Value.Rect.Width / item.Value.Rect.Height;
                double angle = (double)item.Value.Angle();
                if (ratio > 3.5 && ratio < 5.4 && angle > -15 && angle < 15)

                {

                    IplImage texttemp = new IplImage(new CvSize(140, 27), bimg.Depth, bimg.NChannels);

                 // texttemp.Flip( null , FlipMode.X );


                    Cv.Resize(bimg, texttemp);

                    text.Add(texttemp);
                    frame.Rectangle(item.Value.Rect, new CvScalar(0, 0, 255), 2, LineType.Link4);
                 //   frame.Flip(null, FlipMode.X);
              //   frame.Rectangle(item.Value.Rect, new CvScalar(0, 0, 255), 2, LineType.Link4)=RotateFlipType.Rotate180FlipNone()
                   // RotateFlipType.Rotate180FlipX(frame.Rectangle(item.Value.Rect, new CvScalar(0, 0, 255), 2, LineType.Link4));
                  // flipImage=frame.Rectangle(item.Value.Rect, new CvScalar(0, 0, 255), 2, LineType.Link4);
                }
            }

            textList.Clear();

        }
        return pathImage;
    }
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
j.doe
  • 327
  • 7
  • 22

1 Answers1

2

I don't have the reputation needed to comment, so this will have to be in the form of an answer. It looks like pathImage doesn't get any value after you do all the processing to find the text - it keeps the value of imgPath, so you just return the same value you put in.

  • Thanks your comment Pathımage get a value but I forgat add these code in here In addition When I put a debug my code is going all the processing :( If you want ı can add these code in here – j.doe May 23 '16 at 13:52
  • Maybe look at the following link before adding more code here: http://stackoverflow.com/questions/34366083/i-need-recognize-text-in-image-using-opencvsharp – Mahendran Nadesan May 23 '16 at 13:55
  • 1
    Thank you so much but I read it our problem and codes are different but ı will read it again – j.doe May 23 '16 at 13:57
  • I don't know enough about this to help, but if you can't debug, you should add some logging to help you. An example: `IplImage imgTemp = frame.Clone(); Console.Writeline("Value of frame is " + frame.someProperty); Console.Writeline("Value of temp is " + imgTemp.someProperty);` – Mahendran Nadesan May 23 '16 at 14:03
  • 1
    Thank you but I can debug and code is entering all processing so ı dont know where my is wrong – j.doe May 23 '16 at 14:31
  • You are going to have to set breakpoints and check the values, then compare them to expected values. Maybe find some sample code, and compare similar variables. What format are you trying to get the text in? Make sure your types are correct - should you be returning strings anywhere? Try analysing it backwards - start with the text you expect, and try to get the values of the variables immediately before conversion to text. Good luck! – Mahendran Nadesan May 23 '16 at 15:28