作者:tonycomin
项目:go-opencv-
func Rectangle(image *IplImage, pt1, pt2 Point, color Scalar, thickness, line_type, shift int) {
C.cvRectangle(
unsafe.Pointer(image),
C.cvPoint(C.int(pt1.X), C.int(pt1.Y)),
C.cvPoint(C.int(pt2.X), C.int(pt2.Y)),
(C.CvScalar)(color),
C.int(thickness), C.int(line_type), C.int(shift),
)
}
作者:masu-m
项目:face_detecto
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,
)
}
}
作者:tonycomin
项目:go-opencv-
// void cvPutText(CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color)
func (this *Font) PutText(image *IplImage, text string, pt1 Point, color Scalar) {
C.cvPutText(
unsafe.Pointer(image),
C.CString(text),
C.cvPoint(C.int(pt1.X), C.int(pt1.Y)),
&this.font,
(C.CvScalar)(color),
)
}
作者:tonycomin
项目:go-opencv-
func Circle(image *IplImage, pt1 Point, radius int, color Scalar, thickness, line_type, shift int) {
C.cvCircle(
unsafe.Pointer(image),
C.cvPoint(C.int(pt1.X), C.int(pt1.Y)),
C.int(radius),
(C.CvScalar)(color),
C.int(thickness), C.int(line_type), C.int(shift),
)
}
作者:sdob
项目:go-openc
//cvDrawContours(CvArr* img, CvSeq* contour, CvScalar externalColor, CvScalar holeColor, int maxLevel, int thickness=1, int lineType=8
func DrawContours(image *IplImage, contours *Seq, externalColor, holeColor Scalar, maxLevel, thickness, lineType int, offset Point) {
C.cvDrawContours(
unsafe.Pointer(image),
(*C.CvSeq)(contours),
(C.CvScalar)(externalColor),
(C.CvScalar)(holeColor),
C.int(maxLevel),
C.int(thickness),
C.int(lineType),
C.cvPoint(C.int(offset.X), C.int(offset.Y)))
}
作者:sdob
项目:go-openc
/* Returns a Seq of countours in an image, detected according to the parameters.
Caller must Release() the Seq returned */
func (image *IplImage) FindContours(mode, method int, offset Point) *Seq {
storage := C.cvCreateMemStorage(0)
header_size := (C.size_t)(unsafe.Sizeof(C.CvContour{}))
var seq *C.CvSeq
C.cvFindContours(
unsafe.Pointer(image),
storage,
&seq,
C.int(header_size),
C.int(mode),
C.int(method),
C.cvPoint(C.int(offset.X), C.int(offset.Y)))
return (*Seq)(seq)
}
作者:bonl
项目:exercis
func main() {
fmt.Println("Hello World!")
text := C.CString("Hello World!")
defer C.free(unsafe.Pointer(text))
C.cvNamedWindow(text, 1)
img := unsafe.Pointer(C.cvCreateImage(C.cvSize(640, 480), C.IPL_DEPTH_8U, 1))
C.cvSet(img, C.cvScalar(0, 0, 0, 0), nil)
var font C.CvFont
C.cvInitFont(&font, C.CV_FONT_HERSHEY_SIMPLEX|C.CV_FONT_ITALIC,
1.0, 1.0, 0, 1, 8)
C.cvPutText(img, text, C.cvPoint(200, 400), &font,
C.cvScalar(255, 255, 0, 0))
C.cvShowImage(text, img)
C.cvWaitKey(0)
}
作者:bradh
项目:go-openc
func (self Point) AsCvPoint() C.CvPoint {
return C.cvPoint(C.int(self.X), C.int(self.Y))
}
作者:MeasureTheFutur
项目:scou
func measure(deltaC chan Command, videoFile string, debug bool, config Configuration) {
camera, err := getVideoSource(videoFile)
if err != nil {
// No valid video source. Abort measuring.
log.Printf("ERROR: Unable to get video source")
log.Print(err)
return
}
defer C.cvReleaseCapture(&camera)
// Make sure we release the camera when the operating system crushes us.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
log.Printf("INFO: The OS shut down the scout.")
C.cvReleaseCapture(&camera)
return
}()
scene := initScene()
// Build the calibration frame from disk.
var calibrationFrame *C.IplImage
if _, err := os.Stat("calibrationFrame.jpg"); err == nil {
file := C.CString("calibrationFrame.jpg")
calibrationFrame = C.cvLoadImage(file, C.CV_LOAD_IMAGE_COLOR)
defer C.cvReleaseImage(&calibrationFrame)
C.free(unsafe.Pointer(file))
} else {
log.Printf("ERROR: Unable to measure, missing calibration frame")
log.Print(err)
return
}
// Create a frame to hold the foreground mask results.
mask := C.cvCreateImage(C.cvSize(calibrationFrame.width, calibrationFrame.height), C.IPL_DEPTH_8U, 1)
defer C.cvReleaseImage(&mask)
// Push the initial calibration frame into the MOG2 image subtractor.
C.initMOG2(C.int(config.MogHistoryLength), C.double(config.MogThreshold), C.int(config.MogDetectShadows))
C.applyMOG2(unsafe.Pointer(calibrationFrame), unsafe.Pointer(mask))
// Current frame counter.
frame := int64(0)
measuring := true
// Start monitoring from the camera.
for measuring && C.cvGrabFrame(camera) != 0 {
// See if there are any new commands on the deltaC channel.
select {
case c := <-deltaC:
switch {
case c == STOP_MEASURE:
log.Printf("INFO: Stopping measure")
measuring = false
}
default:
// Procceed with measuring.
}
// Subtract the calibration frame from the current frame.
nextFrame := C.cvRetrieveFrame(camera, 0)
C.applyMOG2(unsafe.Pointer(nextFrame), unsafe.Pointer(mask))
// Filter the foreground mask to clean up any noise or holes (morphological-closing).
C.cvSmooth(unsafe.Pointer(mask), unsafe.Pointer(mask), C.CV_GAUSSIAN, C.int(config.GaussianSmooth), 0, 0.0, 0.0)
C.cvThreshold(unsafe.Pointer(mask), unsafe.Pointer(mask), C.double(config.ForegroundThresh), 255, 0)
C.cvDilate(unsafe.Pointer(mask), unsafe.Pointer(mask), nil, C.int(config.DilationIterations))
// Detect contours in filtered foreground mask
storage := C.cvCreateMemStorage(0)
contours := C.cvCreateSeq(0, C.size_t(unsafe.Sizeof(C.CvSeq{})), C.size_t(unsafe.Sizeof(C.CvPoint{})), storage)
offset := C.cvPoint(C.int(0), C.int(0))
num := int(C.cvFindContours(unsafe.Pointer(mask), storage, &contours, C.int(unsafe.Sizeof(C.CvContour{})),
C.CV_RETR_LIST, C.CV_CHAIN_APPROX_SIMPLE, offset))
var detectedObjects []Waypoint
// Track each of the detected contours.
for contours != nil {
area := float64(C.cvContourArea(unsafe.Pointer(contours), C.cvSlice(0, 0x3fffffff), 0))
// Only track large objects.
if area > config.MinArea {
boundingBox := C.cvBoundingRect(unsafe.Pointer(contours), 0)
w := int(boundingBox.width / 2)
h := int(boundingBox.height / 2)
x := int(boundingBox.x) + w
y := int(boundingBox.y) + h
detectedObjects = append(detectedObjects, Waypoint{x, y, w, h, 0.0})
if debug {
// DEBUG -- Render contours and bounding boxes around detected objects.
pt1 := C.cvPoint(boundingBox.x, boundingBox.y)
pt2 := C.cvPoint(boundingBox.x+boundingBox.width, boundingBox.y+boundingBox.height)
//.........这里部分代码省略.........