首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用JavaCV识别特定对象

如何使用JavaCV识别特定对象
EN

Stack Overflow用户
提问于 2013-10-18 18:53:13
回答 1查看 2.5K关注 0票数 0

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

代码语言:javascript
复制
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个医生对象的彩色图像,输出是检测工具的灰度图像。抱歉,系统不允许上传图片。

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

EN

回答 1

Stack Overflow用户

发布于 2014-03-01 02:42:58

它可以实现使用Haar Casacde文件的内置数据-在google提供的Haar文件中可以找到opencv\ .Some \haarcascades目录下的.These文件是XML文件通过重训练生成的示例sections.Some的haar文件用于人脸检测、耳朵检测等。一个示例工程可以在here上创建.You可以生成自己的任意purpose.one的haar级联文件的方法可以在here上找到

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19447885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档