Ask Your Question

benreghaimehdi's profile - activity

2020-01-16 23:10:21 -0500 received badge  Popular Question (source)
2017-01-04 06:18:02 -0500 asked a question Find square checked

Hello, I want my program (in java) to input an image input and output a string like :

  • Question 1: box 2 checked
  • Question 2: box 1 checked
  • Question 3: box 3 checked
  • Question 4: box 2 checked ... (as many question as I have per image)

Thank you for help !

2016-12-31 12:50:07 -0500 commented question find contour opencv java

At the image level yes. But I want the program not release me an output image but rather strings of characters like:

  • Question 1: box 2 checked
  • Question 2: box 1 checked
  • Question 3: box 3 checked
  • Question 4: box 2 checked

Thanks for help !!

2016-12-31 10:10:44 -0500 asked a question find contour opencv java

Hello, I want my program to input an image (attachment) image description

and output a string like :

  • Question 1: box 2 checked
  • Question 2: box 1 checked
  • Question 3: box 3 checked
  • Question 4: box 2 checked

Etc ... (as many question as I have per image)

I can simply locate empty boxes with this program:

import java.util.ArrayList;
import java.util.List;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;public class test {
public static void main(String[] args) {
    // Load the library of openCv
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    // Consider the image for processing
    Mat image = Imgcodecs.imread("C:/attachement.jpg", Imgproc.COLOR_BGR2GRAY);
    Mat imageHSV = new Mat(image.size(), CvType.CV_8UC4);
    Mat imageBlurr = new Mat(image.size(),CvType.CV_8UC4);
    Mat imageA = new Mat(image.size(), CvType.CV_32F);
    Imgproc.cvtColor(image, imageHSV, Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(imageHSV, imageBlurr, new Size(5,5), 0);
    Imgproc.adaptiveThreshold(imageBlurr, imageA, 255,Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY,7, 5);
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();    
    Imgproc.findContours(imageA, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
    for(int i=0; i< contours.size();i++)
    {
        if (Imgproc.contourArea(contours.get(i)) > 50 )
        {
            Rect rect = Imgproc.boundingRect(contours.get(i));
            if ((rect.height > 35 && rect.height < 60) && (rect.width > 35 && rect.width < 60))
            {
                Imgproc.rectangle(image, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(0,0,255));
            }
        }
    }
    Imgcodecs.imwrite("C:/Users/Benreghai/Downloads/tof/output.png",image);
}

}

Here is the output of my program: (image attached) output

Thank you for your help !