我正在尝试使用以下代码从内窥镜视频中检测医生的工具
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归档我的目标吗?
发布于 2014-03-01 02:42:58
它可以实现使用Haar Casacde文件的内置数据-在google提供的Haar文件中可以找到opencv\ .Some \haarcascades目录下的.These文件是XML文件通过重训练生成的示例sections.Some的haar文件用于人脸检测、耳朵检测等。一个示例工程可以在here上创建.You可以生成自己的任意purpose.one的haar级联文件的方法可以在here上找到
https://stackoverflow.com/questions/19447885
复制相似问题