Пример #1
0
/****************************************************************************************\
*                           More operations on sequences                                 *
\****************************************************************************************/
func (self Seq) ForEach(t reflect.Type, callback func(interface{})) {
	c_seq := (*C.CvSeq)(&self)
	seqLen := int(c_seq.total)

	for i := 0; i < seqLen; i++ {
		c_obj := C.cvGetSeqElem(c_seq, C.int(i))
		obj := reflect.NewAt(t, unsafe.Pointer(c_obj))
		callback(obj.Interface())
	}
}
Пример #2
0
func (this *HaarCascade) DetectObjects(image *IplImage) []*Rect {
	storage := C.cvCreateMemStorage(0)
	seq := C.cvHaarDetectObjects(unsafe.Pointer(image), this.cascade, storage, 1.1, 3, C.CV_HAAR_DO_CANNY_PRUNING, C.cvSize(0, 0), C.cvSize(0, 0))
	var faces []*Rect
	for i := 0; i < (int)(seq.total); i++ {
		rect := (*Rect)((*_Ctype_CvRect)(unsafe.Pointer(C.cvGetSeqElem(seq, C.int(i)))))
		faces = append(faces, rect)
	}
	return faces
}
Пример #3
0
func addRectanglesToImage(img *C.IplImage, cvRects *C.CvSeq) {
	for i := C.int(0); i < cvRects.total; i++ {
		rect := (*C.CvRect)(unsafe.Pointer(C.cvGetSeqElem(cvRects, i)))
		C.cvRectangle(
			unsafe.Pointer(img),
			C.cvPoint(rect.x, rect.y),
			C.cvPoint(rect.x+rect.width, rect.y+rect.height),
			C.cvScalar(0, 0, 255, 0),
			3,
			C.CV_AA,
			0,
		)
	}
}
Пример #4
0
func convertToRectagles(cvRects *C.CvSeq) [][4]int {
	result := make([][4]int, 0, cvRects.total)
	for i := C.int(0); i < cvRects.total; i++ {
		cvRect := (*C.CvRect)(unsafe.Pointer(C.cvGetSeqElem(cvRects, i)))
		result = append(
			result,
			[4]int{
				int(cvRect.x), int(cvRect.y),
				int(cvRect.x + cvRect.width), int(cvRect.y + cvRect.height),
			},
		)
	}
	return result
}