[英]How to convert this code into javacv?
I had went through many tutorials and guide lines and I was able to convert part of it. 我经历了许多教程和指南,并且能够转换其中的一部分。 But I don't know how to convert last line in to javacv. 但是我不知道如何将最后一行转换为javacv。 So Please can some one help me to convert this code in to javacv? 因此,请有人可以帮助我将此代码转换为javacv吗?
img = cv2.imread('sofud.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,127,255,1)
contours,hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
if 10 < w/float(h) or w/float(h) < 0.1:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
You can use the last line as this in Java CV: 您可以在Java CV中使用最后一行:
opencv_core.cvRectangle(image, opencv_core.cvPoint(m,n), opencv_core.cvPoint(i,j), opencv_core.cvScalar(0,0,255,0), thickness, 8, 0);
Where the parameters mean: 参数含义:
opencv_core.cvRectangle(CvArr* img, CvPoint , CvPoint, CvScalar color, int thickness=1, int lineType=8, int shift=0)
and look at this Link for more information. 并查看此链接以获取更多信息。
EDIT: 编辑:
This is an example of finding contours: 这是查找轮廓的示例:
cvFindContours(grayImage, memory, contours, sizeof(CvContour.class) , CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
Where the parameter mean: 参数含义:
cvFindContours(CvArr* image, CvMemStorage* storage, CvSeq** first_contour, int header_size=sizeof(CvContour), int mode=CV_RETR_LIST, int method=CV_CHAIN_APPROX_SIMPLE, CvPoint offset=cvPoint(0,0) )
For more information on the parameters, take a look at this Link , under FindContours
section. 有关参数的更多信息,请在FindContours
部分下查看此Link 。
You can also use the cvDrawContours
function, to draw the contours in the same way as we have used cvFindContours
function. 您还可以使用cvDrawContours
函数以与使用cvFindContours
函数相同的方式绘制轮廓。
Take a look at this Link . 看一下这个Link 。 It is a different post on this website in which the they have explained the use of finding contours in blob detection. 这是该网站上的另一篇文章,他们解释了在斑点检测中寻找轮廓的用途。
Hope This Helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.