Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用hough法检测瞳孔的最佳参数?java opencv_Java_Opencv_Detection_Hough Transform_Iris Recognition - Fatal编程技术网

用hough法检测瞳孔的最佳参数?java opencv

用hough法检测瞳孔的最佳参数?java opencv,java,opencv,detection,hough-transform,iris-recognition,Java,Opencv,Detection,Hough Transform,Iris Recognition,--------------阅读下面的编辑--------------- 我试图在各种图像中检测瞳孔和虹膜的边缘。我正在改变参数等,但我只能设法得到一个虹膜/瞳孔轮廓正确,或得到背景中不必要的轮廓,或根本没有。是一些具体的参数,我应该尝试得到正确的轮廓。或者有没有一种方法可以将图像裁剪到眼睛上,这样系统就可以聚焦到这一部分 这是我更新的方法: private void findPupilIris() throws IOException { //converts and saves im

--------------阅读下面的编辑--------------- 我试图在各种图像中检测瞳孔和虹膜的边缘。我正在改变参数等,但我只能设法得到一个虹膜/瞳孔轮廓正确,或得到背景中不必要的轮廓,或根本没有。是一些具体的参数,我应该尝试得到正确的轮廓。或者有没有一种方法可以将图像裁剪到眼睛上,这样系统就可以聚焦到这一部分

这是我更新的方法:

private void findPupilIris() throws IOException {
    //converts and saves image in grayscale

    Mat newimg = Imgcodecs.imread("/Users/.../pic.jpg");
    Mat des = new Mat(newimg.rows(), newimg.cols(), newimg.type());
    Mat norm = new Mat();

    Imgproc.cvtColor(newimg, des, Imgproc.COLOR_BGR2HSV);
    List<Mat> hsv = new ArrayList<Mat>();
    Core.split(des, hsv);
    Mat v = hsv.get(2); //gets the grey scale version

    Imgcodecs.imwrite("/Users/Lisa-Maria/Documents/CapturedImages/B&Wpic.jpg", v); //only writes mats

    CLAHE clahe = Imgproc.createCLAHE(2.0, new Size(8,8) ); //2.0, new Size(8,8) 
    clahe.apply(v,v);
//    Imgproc.GaussianBlur(v, v, new Size(9,9), 3); //adds left pupil boundary and random circle on 'a'
 //   Imgproc.GaussianBlur(v, v, new Size(9,9), 13); //adds right outer iris boundary and random circle on 'a'
    Imgproc.GaussianBlur(v, v, new Size(9,9), 7);  //adds left outer iris boundary and random circle on left by hair
  //  Imgproc.GaussianBlur(v, v, new Size(7,7), 15);
    Core.addWeighted(v, 1.5, v, -0.5, 0, v);


    Imgcodecs.imwrite("/Users/.../after.jpg", v); //only writes mats
    if (v != null) {
        Mat circles = new Mat();

        Imgproc.HoughCircles( v, circles, Imgproc.CV_HOUGH_GRADIENT, 2, v.rows(), 100, 20, 20, 200 );

        List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

        System.out.println("circles.cols() " + circles.cols());
        if(circles.cols() > 0) {
            System.out.println("1");
            for (int x = 0; x < circles.cols(); x++) {
                System.out.println("2");
                double vCircle[] = circles.get(0, x);


                if(vCircle == null) {
                    break;
                }

                Point pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
                int radius = (int) Math.round(vCircle[2]);

                //draw the found circle




                Imgproc.circle(v, pt, radius, new Scalar(255,0,0),2); //newimg
                //Imgproc.circle(des, pt, radius/3, new Scalar(225,0,0),2); //pupil
                Imgcodecs.imwrite("/Users/.../Houghpic.jpg", v); //newimg

                //draw the mask: white circle on black background
//                  Mat mask = new Mat( new Size( des.cols(), des.rows() ), CvType.CV_8UC1 );
//                  Imgproc.circle(mask, pt, radius, new Scalar(255,0,0),2); 

//                  des.copyTo(des,mask);
//                  Imgcodecs.imwrite("/Users/..../mask.jpg", des); //newimg


                Imgproc.logPolar(des, norm, pt, radius, Imgproc.WARP_FILL_OUTLIERS);
                Imgcodecs.imwrite("/Users/..../Normalised.jpg",norm);
            }
        }
    }
}
private void findPupilIris()引发IOException{
//转换并保存灰度图像
Mat newimg=Imgcodecs.imread(“/Users/../pic.jpg”);
Mat des=new Mat(newimg.rows(),newimg.cols(),newimg.type());
材料规范=新材料();
Imgproc.CVT颜色(新IMG、des、Imgproc.COLOR\U BGR2HSV);
List hsv=new ArrayList();
分芯(des、hsv);
Mat v=hsv.get(2);//获取灰度版本
Imgcodecs.imwrite(“/Users/Lisa Maria/Documents/CapturedImages/B&Wpic.jpg”,v);//只写mats
CLAHE CLAHE=Imgproc.createCLAHE(2.0,新大小(8,8));//2.0,新大小(8,8)
申请类别(v,v);
//GaussianBlur(v,v,新尺寸(9,9),3);//在“a”上添加左瞳孔边界和随机圆
//GaussianBlur(v,v,新尺寸(9,9),13);//在“a”上添加右外虹膜边界和随机圆
GaussianBlur(v,v,新尺寸(9,9),7);//添加左侧虹膜外边界和头发左侧的随机圆
//GaussianBlur(v,v,新尺寸(7,7),15);
核心加权(v,1.5,v,-0.5,0,v);
Imgcodecs.imwrite(“/Users/../after.jpg”,v);//只写mats
如果(v!=null){
垫圆=新垫();
Imgproc.HOUGH圆(v,圆,Imgproc.CV_-HOUGH_梯度,2,v.rows(),100,20,20,200);
列表等高线=新的ArrayList();
System.out.println(“circles.cols()”+circles.cols());
if(circles.cols()>0){
系统输出打印项次(“1”);
对于(int x=0;x

结果:

在评论中讨论之后,我发布了一个一般性的答案,其中包含了我在OP上传的最坏情况图片上得到的一些结果

注意:我发布的代码是用Python编写的,因为它是我编写的最快的

第一步。当你要求一种裁剪图像的方法,以便只聚焦在眼睛上时,你可能想看看。由于图像基本上只需要找到眼睛,因此我做了以下操作:

eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
eyes = eye_cascade.detectMultiScale(v) // v is the value channel of the HSV image
// The results "eyes" gives you the dimensions of the rectangle where the eyes are detected as [x, y, w, h]
// Just for drawing 
cv2.rectangle(v, (x1, y1), (x1+w1, y1+h1), (0, 255, 0), 2)
cv2.rectangle(v, (x2, y2), (x2+w2, y2+h2), (0, 255, 0), 2)

现在,一旦有了边界矩形,就可以从图像中裁剪矩形,如下所示:

crop_eye1 = v[y1:y1+h1, x1:x1+w1]
crop_eye2 = v[y2:y2+h2, x2:x2+w2]
获得矩形后,我建议您查看不同的颜色空间,而不是RGB/BGR,尤其是HSV/Lab/Luv

由于数字图像中物体颜色的R、G和B分量都与照射到物体上的光量相关,因此相互关联,因此根据这些分量的图像描述使得物体识别困难。色调/亮度/色度或色调/亮度/饱和度方面的描述通常更相关

然后,一旦你有了眼睛,是时候平衡图像的对比度了,但是,我建议使用并使用
clipLimit
tileGridSize
的参数。下面是我不久前用Java实现的代码:

private static Mat clahe(Mat image, int ClipLimit, Size size){
  CLAHE clahe = Imgproc.createCLAHE();
  clahe.setClipLimit(ClipLimit);
  clahe.setTilesGridSize(size);
  Mat dest_image = new Mat();
  clahe.apply(image, dest_image);
  return dest_image;
}     
一旦你满意了,你就应该锐化图像,使其更加健壮。你应该看看。以下是用Java实现的反锐化掩码的Java代码:

private static Mat unsharpMask(Mat input_image, Size size, double sigma){

// Make sure the {input_image} is gray.
  Mat sharpend_image = new Mat(input_image.rows(), input_image.cols(), input_image.type());
  Mat Blurred_image = new Mat(input_image.rows(), input_image.cols(), input_image.type());
  Imgproc.GaussianBlur(input_image, Blurred_image, size, sigma);
  Core.addWeighted(input_image, 2.0D, Blurred_image, -1.0D, 0.0D, sharpened_image);
  return sharpened_image;
}
或者,您可以使用,这是边缘保持平滑,或通读定义一个自定义内核来锐化图像。
希望这对你有帮助,祝你好运

你为什么发帖?因为我更改了它,我要删除另一个,我现在只能偶尔检测瞳孔/虹膜边缘。那么新的过滤器对你有用吗?哪一个?我已经做了一个编辑来解释发生了什么,谢谢:)啊,谢谢你,我对我的代码做了一些编辑,你会说代码现在是正确的吗?而且它似乎确实改善了hough的效果,我想我需要让学生的轮廓稍微大一点,thoughGreat!让我知道它是如何运行的,如果它有效,请接受它作为未来观众的答案!