Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys
please download the project
you can find it here : https://ufile.io/95n4z6yz[^]
it is c# app for image processing
after run the app
please add 222.jpg file to it
then work with software
i would like to that my software only find 2 lines (same 224.jpg)
and software know that 2 lines (and name them line1 and line2)
thanks
if you can help me
i have other codes (i can draw automatically many parallel lines between line1 and line2)
thanks

What I have tried:

C#
<pre>using System;
using System.Drawing;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;

namespace PictureViewer
{
    public partial class chbFillterOnColor : Form
    {
        //---Variables--//

        bool blnFirstTimeInResizeEvent = true;

        Image<Bgr, Byte> imgOriginal;
        Image<Bgr, Byte> imgSmoothed;
        Image<Gray, Byte> imgGrayColorFiltered;
        Image<Gray, Byte> imgCanny;
        Image<Bgr, Byte> imgLines;
        Double dbMinBlue = 0.0;
        double dbMinGreen = 0.0;
        double dbMinRed = 0.0;
        double dbMaxBlue = 0.0;
        double dbMaxGreen = 0.0;
        double dbMaxRed = 0.0;

        public chbFillterOnColor()
        {
            InitializeComponent();
        }

            private void Form1_Resize(object sender, EventArgs e)
            {
                if (blnFirstTimeInResizeEvent == true)
                {
                    blnFirstTimeInResizeEvent = false;
                }
            }

            private void btnFile_Click(object sender, EventArgs e)
            {
                if (ofdFile.ShowDialog() == DialogResult.OK)
                {
                    Image inputImage = Image.FromFile(ofdFile.FileName);
                    txtFile.Text = ofdFile.FileName.ToString();
                    ProcessImageAndUpdateGUI(new object(), new EventArgs());
                }
            }

            private void chbFillter_CheckedChanged(object sender, EventArgs e)
            {
                if (chbFillter.Checked == true)
                {
                    ProcessImageAndUpdateGUI(new object(), new EventArgs());
          
            }
                else if (chbFillter.Checked == false)
                {
                    ProcessImageAndUpdateGUI(new object(), new EventArgs());
                }
            }

            private void txtFile_TextChanged(object sender, EventArgs e)
            {
                txtFile.SelectionStart = txtFile.Text.Length;
            }

            void ProcessImageAndUpdateGUI(object sender, EventArgs e)
            {
            double dblRhoRes = Convert.ToInt32(textBox1.Text);
            int intThreshold = Convert.ToInt32(textBox3.Text);
            double dblMinLineWidth = Convert.ToInt32(textBox4.Text);
            double dblMinGapBetweenLines = Convert.ToInt32(textBox5.Text);
            imgOriginal = new Image<Bgr, Byte>(txtFile.Text);

                if (imgOriginal == null)
                {
                    return;
                }
                imgSmoothed = imgOriginal.PyrDown().PyrUp();
                imgSmoothed._SmoothGaussian(3);

                if (chbFillter.Checked == false)
                {
                    imgGrayColorFiltered = imgSmoothed.InRange(new Bgr(dbMinBlue, dbMinGreen, dbMinRed), new Bgr(dbMaxBlue, dbMaxGreen, dbMaxRed));
                    imgGrayColorFiltered = imgGrayColorFiltered.PyrDown().PyrUp();
                    imgGrayColorFiltered._SmoothGaussian(3);

                }
                else if (chbFillter.Checked == true)
                {
                    imgGrayColorFiltered = imgSmoothed.Convert<Gray, Byte>();
                }

                Gray grayCannyThreshold = new Gray(Convert.ToInt32(textBox6.Text));
                Gray grayCircleAccumThreshold = new Gray(100);
                Gray grayThreshLinking = new Gray(Convert.ToInt32(textBox7.Text));

                imgCanny = imgGrayColorFiltered.Canny(grayCannyThreshold.Intensity, grayThreshLinking.Intensity);

                imgLines = imgOriginal.CopyBlank();

                Double dblThetaRes = 4.0 * (Math.PI / 180.0);
             

                LineSegment2D[] lines = imgCanny.Clone().HoughLinesBinary(dblRhoRes, dblThetaRes, intThreshold, dblMinLineWidth, dblMinGapBetweenLines)[0];

                foreach (LineSegment2D line in lines)
                {
                    imgLines.Draw(line, new Bgr(Color.Red), 1);
                    {
                        imgOriginal.Draw(line, new Bgr(Color.Red), 1);
                    }
                }
        
                ibOriginal.Image = imgOriginal;
                ibGrayColorFilter.Image = imgGrayColorFiltered;
                ibCanny.Image = imgCanny;
                ibLines.Image = imgLines;

        }


    }
    }
Posted
Updated 23-Jul-21 5:53am
Comments
Richard MacCutchan 23-Jul-21 8:05am    
Sorry, this site does not provide free QA testing. If you have a problem with your code then edit your question and provide complete details.

Just because your code compiles, does not mean your code is right! :laugh:
Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.

So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.

Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:
Input   Expected output    Actual output
  1            2                 1
  2            4                 4
  3            6                 9
  4            8                16
Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
C#
private int Double(int value)
   {
   return value * value;
   }

Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
 
Share this answer
 
thanks
i wrote the complete code by hand
but i would like that it work with image processing
i think it is so hard for me
thanks!
 
Share this answer
 
Comments
Patrice T 23-Jul-21 13:26pm    
To discuss with OG, you should have used the 'Have a Question or comment?' at bottom of Solution. Advantage, OG will be notified.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900