如何使用JavaCV识别特定对象 [英] How to identify specific object using JavaCV

查看:349
本文介绍了如何使用JavaCV识别特定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码从内窥镜检查视频中检测医生的工具

I am trying to detect doctor's tools from endoscopy video using the following code

static void video_tracking(){
      //read image
       IplImage orgImg = cvLoadImage("C:/Users/Ioanna/Desktop/pic.png");

       IplImage thresholdImage = hsvThreshold(orgImg);
       cvSaveImage("hsvthreshold.jpg", thresholdImage);
       Dimension position = getCoordinates(thresholdImage);
       System.out.println("Dimension of original Image : " + thresholdImage.width() + " , " + thresholdImage.height());
       System.out.println("Position of red spot    : x : " + position.width + " , y : " + position.height);

   }

   static Dimension getCoordinates(IplImage thresholdImage) {
       int posX = 0;
       int posY = 0;
       CvMoments moments = new CvMoments();
       cvMoments(thresholdImage, moments, 1);
       double momX10 = cvGetSpatialMoment(moments, 1, 0); // (x,y)
       double momY01 = cvGetSpatialMoment(moments, 0, 1);// (x,y)
       double area = cvGetCentralMoment(moments, 0, 0);
       posX = (int) (momX10 / area);
       posY = (int) (momY01 / area);
       return new Dimension(posX, posY);
   }

   static IplImage hsvThreshold(IplImage orgImg) {

       // Convert the image into an HSV image
       IplImage imgHSV = cvCreateImage(cvGetSize(orgImg), 8, 3);

       cvCvtColor(orgImg, imgHSV, CV_BGR2HSV);

       //create a new image that will hold the threholded image
       // 1- color = monochrome
       IplImage imgThreshold = cvCreateImage(cvGetSize(orgImg), orgImg.depth(), 1);

       //do the actual thresholding
       cvInRangeS(imgHSV, cvScalar(13, 0, 0, 0), cvScalar(40, 117, 124, 88), imgThreshold);

       cvReleaseImage(imgHSV);

       cvSmooth(imgThreshold, imgThreshold, CV_MEDIAN, 13);
       // save
       return imgThreshold;
   }

以上代码的输入是带有2个医生物体的彩色图像,输出是检测工具的灰度图像.抱歉,系统不允许上传图像.

The input of the above code is a color image with 2 doctor's object and the output is a grayscale image that detect the tools. Sorry, but the system doesn't allow to upload the images.

问题是我不知道如何找到2个工具的位置并绘制一个矩形.请有人能解释一下如何使用javacv/opencv归档我的目标吗?

The problem is I don't know how to find the position of 2 tools and draw a rectangle. Please can some one explain how to archive my objective using javacv/opencv?

推荐答案

可以使用Haar Casacde文件来实现.google提供的bulit-In Haar文件可以在opencv \ data \ haarcascades目录中找到.这些文件是由训练繁重的部门生成的XML文件.一些示例haar文件用于面部检测,耳朵检测等.示例项目可以在此处

It can be achieve using Haar Casacde files .Some of the bulit-In Haar files provided by google can found in opencv\data\haarcascades directory .These files are XML files generated by heavy training sections.Some of the sample haar files are used for face detection,ear detection etc.A sample project can be fount at here.You can generate your own haar cascade file for any purpose.one of the method for generate Haar cascade file can be found at here

这篇关于如何使用JavaCV识别特定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆