diff --git a/AUTHORS b/AUTHORS index 695a979..cd0fe53 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,4 +3,5 @@ # Initial version authors: ChaiShushan +MohamedHelala diff --git a/opencv/cv.go b/opencv/cv.go index c41ddcc..c91a4c3 100644 --- a/opencv/cv.go +++ b/opencv/cv.go @@ -18,22 +18,6 @@ import ( func init() { } -const ( - CV_BGR2GRAY = C.CV_BGR2GRAY - CV_BGR2BGRA = C.CV_BGR2BGRA - CV_RGBA2BGRA = C.CV_RGBA2BGRA - - CV_BLUR = C.CV_BLUR - - CV_8U = C.CV_8U - CV_8S = C.CV_8S - CV_16U = C.CV_16U - CV_16S = C.CV_16S - CV_32S = C.CV_32S - CV_32F = C.CV_32F - CV_64F = C.CV_64F -) - /* Smoothes array (removes noise) */ func Smooth(src, dst *IplImage, smoothtype, param1, param2 int, param3, param4 float64) { diff --git a/opencv/cxcore.go b/opencv/cxcore.go index 5c8c927..137d4f2 100644 --- a/opencv/cxcore.go +++ b/opencv/cxcore.go @@ -1,6 +1,7 @@ // Copyright 2011 . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// 22/11/2013 Updated by . package opencv @@ -58,11 +59,6 @@ func CreateImage(w, h, depth, channels int) *IplImage { return (*IplImage)(img) } -/* SetData assigns user data to the image header */ -func (img *IplImage) SetData(data unsafe.Pointer, step int) { - C.cvSetData(unsafe.Pointer(img), data, C.int(step)) -} - /* Releases (i.e. deallocates) IPL image header */ func (img *IplImage) ReleaseHeader() { img_c := (*C.IplImage)(img) @@ -75,10 +71,6 @@ func (img *IplImage) Release() { C.cvReleaseImage(&img_c) } -func (img *IplImage) Zero() { - C.cvSetZero(unsafe.Pointer(img)) -} - /* Creates a copy of IPL image (widthStep may differ) */ func (img *IplImage) Clone() *IplImage { p := C.cvCloneImage((*C.IplImage)(img)) @@ -113,58 +105,6 @@ func (img *IplImage) GetROI() Rect { return Rect(r) } -/* -Reshape changes shape of the image without copying data. A value of `0` means -that channels or rows remain unchanged. -*/ -func (img *IplImage) Reshape(channels, rows, _type int) *Mat { - total := img.Width() * img.Height() - header := CreateMat(rows, total/rows, _type) - n := C.cvReshape(unsafe.Pointer(img), (*C.CvMat)(header), C.int(channels), C.int(rows)) - return (*Mat)(n) -} - -/* Get1D return a specific element from a 1-dimensional matrix. */ -func (img *IplImage) Get1D(x int) Scalar { - ret := C.cvGet1D(unsafe.Pointer(img), C.int(x)) - return Scalar(ret) -} - -/* Get2D return a specific element from a 2-dimensional matrix. */ -func (img *IplImage) Get2D(x, y int) Scalar { - ret := C.cvGet2D(unsafe.Pointer(img), C.int(y), C.int(x)) - return Scalar(ret) -} - -/* Get3D return a specific element from a 3-dimensional matrix. */ -func (img *IplImage) Get3D(x, y, z int) Scalar { - ret := C.cvGet3D(unsafe.Pointer(img), C.int(z), C.int(y), C.int(x)) - return Scalar(ret) -} - -/* Set1D sets a particular element in the image */ -func (img *IplImage) Set1D(x int, value Scalar) { - C.cvSet1D(unsafe.Pointer(img), C.int(x), (C.CvScalar)(value)) -} - -/* Set2D sets a particular element in the image */ -func (img *IplImage) Set2D(x, y int, value Scalar) { - C.cvSet2D(unsafe.Pointer(img), C.int(y), C.int(x), (C.CvScalar)(value)) -} - -/* Set3D sets a particular element in the image */ -func (img *IplImage) Set3D(x, y, z int, value Scalar) { - C.cvSet3D(unsafe.Pointer(img), C.int(z), C.int(y), C.int(x), (C.CvScalar)(value)) -} - -/* GetMat returns the matrix header for an image.*/ -func (img *IplImage) GetMat() *Mat { - var null C.int - tmp := CreateMat(img.Height(), img.Width(), CV_32S) - m := C.cvGetMat(unsafe.Pointer(img), (*C.CvMat)(tmp), &null, C.int(0)) - return (*Mat)(m) -} - // mat step const ( CV_AUTOSTEP = C.CV_AUTOSTEP @@ -198,11 +138,6 @@ func (mat *Mat) InitHeader(rows, cols, type_ int, data unsafe.Pointer, step int) ) } -/* SetData assigns user data to the matrix header. */ -func (mat *Mat) SetData(data unsafe.Pointer, step int) { - C.cvSetData(unsafe.Pointer(mat), data, C.int(step)) -} - /* Releases CvMat header and deallocates matrix data (reference counting is used for data) */ func (mat *Mat) Release() { @@ -227,21 +162,6 @@ func (mat *Mat) Clone() *Mat { return (*Mat)(mat_new) } -func (mat *Mat) Zero() { - C.cvSetZero(unsafe.Pointer(mat)) -} - -/* -Reshape changes shape of the matrix without copying data. A value of `0` means -that channels or rows remain unchanged. -*/ -func (m *Mat) Reshape(channels, rows int) *Mat { - total := m.Cols() * m.Rows() - n := CreateMat(rows, total/rows, m.Type()) - C.cvReshape(unsafe.Pointer(m), (*C.CvMat)(n), C.int(channels), C.int(rows)) - return n -} - /* Makes a new matrix from subrectangle of input array. No data is copied */ func GetSubRect(arr Arr, submat *Mat, rect Rect) *Mat { @@ -309,47 +229,6 @@ func GetDiag(arr Arr, submat *Mat, diag int) *Mat { return (*Mat)(mat_new) } -/* Get1D return a specific element from a 1-dimensional matrix. */ -func (m *Mat) Get1D(x int) Scalar { - ret := C.cvGet1D(unsafe.Pointer(m), C.int(x)) - return Scalar(ret) -} - -/* Get2D return a specific element from a 2-dimensional matrix. */ -func (m *Mat) Get2D(x, y int) Scalar { - ret := C.cvGet2D(unsafe.Pointer(m), C.int(x), C.int(y)) - return Scalar(ret) -} - -/* Get3D return a specific element from a 3-dimensional matrix. */ -func (m *Mat) Get3D(x, y, z int) Scalar { - ret := C.cvGet3D(unsafe.Pointer(m), C.int(x), C.int(y), C.int(z)) - return Scalar(ret) -} - -/* Set1D sets a particular element in them matrix */ -func (m *Mat) Set1D(x int, value Scalar) { - C.cvSet1D(unsafe.Pointer(m), C.int(x), (C.CvScalar)(value)) -} - -/* Set2D sets a particular element in them matrix */ -func (m *Mat) Set2D(x, y int, value Scalar) { - C.cvSet2D(unsafe.Pointer(m), C.int(x), C.int(y), (C.CvScalar)(value)) -} - -/* Set3D sets a particular element in them matrix */ -func (m *Mat) Set3D(x, y, z int, value Scalar) { - C.cvSet3D(unsafe.Pointer(m), C.int(x), C.int(y), C.int(z), (C.CvScalar)(value)) -} - -/* GetImage returns the image header for the matrix. */ -func (m *Mat) GetImage(channels int) *IplImage { - tmp := CreateImage(m.Cols(), m.Rows(), m.Type(), channels) - img := C.cvGetImage(unsafe.Pointer(m), (*C.IplImage)(tmp)) - - return (*IplImage)(img) -} - /* low-level scalar <-> raw data conversion functions */ func ScalarToRawData(scalar *Scalar, data unsafe.Pointer, type_, extend_to_12 int) { C.cvScalarToRawData( @@ -468,6 +347,35 @@ func (iter *SparseMatIterator) Next() *SparseNode { // P290 + +// +// +// + +/* Converts CvArr (IplImage or CvMat,...) to CvMat. + If the last parameter is non-zero, function can + convert multi(>2)-dimensional array to CvMat as long as + the last array's dimension is continous. The resultant + matrix will be have appropriate (a huge) number of rows + + CVAPI(CvMat*) cvGetMat( const CvArr* arr, CvMat* header, + int* coi CV_DEFAULT(NULL),int allowND CV_DEFAULT(0));*/ +func GetMat(arr unsafe.Pointer, header *Mat, coi *int32, allowND int) *Mat{ + m := C.cvGetMat(arr, (*C.CvMat)(header), (*C.int)(coi), C.int(allowND)) + return (*Mat)(m) +} + +/* Converts CvArr (IplImage or CvMat) to IplImage + + CVAPI(IplImage*) cvGetImage( const CvArr* arr, + IplImage* image_header );*/ +func GetImage(arr unsafe.Pointer, header *IplImage) *IplImage{ + m := C.cvGetImage(arr, (*C.IplImage)(header)) + return (*IplImage)(m) +} + + + /* Returns width and height of array in elements */ func GetSizeWidth(img *IplImage) int { size := C.cvGetSize(unsafe.Pointer(img)) @@ -486,16 +394,16 @@ func GetSize(img *IplImage) Size { } /* Copies source array to destination array */ -func Copy(src, dst, mask *IplImage) { - C.cvCopy(unsafe.Pointer(src), unsafe.Pointer(dst), unsafe.Pointer(mask)) +func Copy(src, dst, mask unsafe.Pointer) { + C.cvCopy(src, dst, mask) } //CVAPI(void) cvCopy( const CvArr* src, CvArr* dst, // const CvArr* mask CV_DEFAULT(NULL) ); /* Clears all the array elements (sets them to 0) */ -func Zero(img *IplImage) { - C.cvSetZero(unsafe.Pointer(img)) +func Zero(img unsafe.Pointer) { + C.cvSetZero(img) } //CVAPI(void) cvSetZero( CvArr* arr ); @@ -532,44 +440,356 @@ func Not(src, dst *IplImage) { * Dynamic data structures * \****************************************************************************************/ +/* Calculates length of sequence slice (with support of negative indices). */ + +func SliceLength(slice Slice, seq *Seq) { + C.cvSliceLength(C.CvSlice(slice), (*C.CvSeq)(seq)) +} + +// CVAPI(int) cvSliceLength( CvSlice slice, const CvSeq* seq ); + +/* Creates new memory storage. + block_size == 0 means that default, + somewhat optimal size, is used (currently, it is 64K) */ +func CreateMemStorage(block_size int) *MemStorage { + block := C.cvCreateMemStorage(C.int(block_size)) + return (*MemStorage)(block) +} + +// CVAPI() cvCreateMemStorage( int block_size CV_DEFAULT(0)); + +/* Creates a memory storage that will borrow memory blocks from parent storage */ +func CreateChildMemStorage(parent *MemStorage) *MemStorage { + block := C.cvCreateChildMemStorage((*C.CvMemStorage)(parent)) + return (*MemStorage)(block) +} + +// CVAPI(CvMemStorage*) cvCreateChildMemStorage( CvMemStorage* parent ); + +/* Releases memory storage. All the children of a parent must be released before + the parent. A child storage returns all the blocks to parent when it is released */ +func ReleaseMemStorage(storage *MemStorage) { + block := (*C.CvMemStorage)(storage) + C.cvReleaseMemStorage(&block) +} + +// CVAPI(void) cvReleaseMemStorage( CvMemStorage** storage ); + +/* Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos) + to reuse memory allocated for the storage - cvClearSeq,cvClearSet ... + do not free any memory. + A child storage returns all the blocks to the parent when it is cleared */ +func ClearMemStorage(storage *MemStorage) { + C.cvClearMemStorage((*C.CvMemStorage)(storage)) +} + +// CVAPI(void) cvClearMemStorage( CvMemStorage* storage ); + +/* Remember a storage "free memory" position */ +func SaveMemStoragePos(storage *MemStorage, pos *MemStoragePos) { + C.cvSaveMemStoragePos((*C.CvMemStorage)(storage), (*C.CvMemStoragePos)(pos)) +} + +// CVAPI(void) cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos ); + +/* Restore a storage "free memory" position */ +func RestoreMemStoragePos(storage *MemStorage, pos *MemStoragePos) { + C.cvRestoreMemStoragePos((*C.CvMemStorage)(storage), (*C.CvMemStoragePos)(pos)) +} + +// CVAPI(void) cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos ); + +/* Allocates continuous buffer of the specified size in the storage */ +func MemStorageAlloc(storage *MemStorage, size int) { + C.cvMemStorageAlloc((*C.CvMemStorage)(storage), C.size_t(size)) +} + +// CVAPI(void*) cvMemStorageAlloc( CvMemStorage* storage, size_t size ); + +/* Allocates string in memory storage */ +func MemStorageAllocString(storage *MemStorage, name string, _len int) { + C.cvMemStorageAllocString((*C.CvMemStorage)(storage), C.CString(name), C.int(_len)) +} + +// CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, +// int len CV_DEFAULT(-1) ); + +/* Creates new empty sequence that will reside in the specified storage */ +func CreateSeq(seq_flags, header_size, elem_size int, storage *MemStorage) { + C.cvCreateSeq(C.int(seq_flags), C.size_t(header_size), C.size_t(elem_size), (*C.CvMemStorage)(storage)) +} + +//CVAPI(CvSeq*) cvCreateSeq( int seq_flags, size_t header_size, +// size_t elem_size, CvMemStorage* storage ); + +/* Removes all the elements from the sequence. The freed memory + can be reused later only by the same sequence unless cvClearMemStorage + or cvRestoreMemStoragePos is called */ +func ClearSeq(seq *Seq) { + C.cvClearSeq((*C.CvSeq)(seq)) +} + +// CVAPI(void) cvClearSeq( CvSeq* seq ); + +/* Retrieves pointer to specified sequence element. + Negative indices are supported and mean counting from the end + (e.g -1 means the last sequence element) */ +func GetSeqElem(seq *Seq, index int) *int8 { + el := C.cvGetSeqElem((*C.CvSeq)(seq), C.int(index)) + return (*int8)(el) +} + +// CVAPI(schar*) cvGetSeqElem( const CvSeq* seq, int index ); + +/* Calculates index of the specified sequence element. + Returns -1 if element does not belong to the sequence */ +func SeqElemIdx(seq *Seq, el unsafe.Pointer, seqblock *SeqBlock) int { + cvseqblock := (*C.CvSeqBlock)(seqblock) + r := C.cvSeqElemIdx((*C.CvSeq)(seq), el, &cvseqblock) + return (int)(r) +} + +// CVAPI(int) cvSeqElemIdx( const CvSeq* seq, const void* element, +// CvSeqBlock** block CV_DEFAULT(NULL) ); + +/* Extracts sequence slice (with or without copying sequence elements) */ +func SeqSlice(seq *Seq, slice Slice, storage *MemStorage, copy_data int) *Seq { + r := C.cvSeqSlice((*C.CvSeq)(seq), C.CvSlice(slice), (*C.CvMemStorage)(storage), C.int(copy_data)) + return (*Seq)(r) +} + +// CVAPI(CvSeq*) cvSeqSlice( const CvSeq* seq, CvSlice slice, +// CvMemStorage* storage CV_DEFAULT(NULL), +// int copy_data CV_DEFAULT(0)); +/* A wrapper for the somewhat more general routine cvSeqSlice() whuch +creates a deep copy of a sequence and creates another entirely separate +sequence structure.*/ +func CloneSeq(seq *Seq, storage *MemStorage) *Seq { + r := C.cvSeqSlice((*C.CvSeq)(seq), (C.CvSlice)(CV_WHOLE_SEQ), (*C.CvMemStorage)(storage), C.int(1)) + return (*Seq)(r) +} + +// CV_INLINE CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL)) +// { +// return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 ); +// } + +/* Removes sequence slice */ +func SeqRemoveSlice(seq *Seq, slice Slice) { + C.cvSeqRemoveSlice((*C.CvSeq)(seq), C.CvSlice(slice)) +} + +// CVAPI(void) cvSeqRemoveSlice( CvSeq* seq, CvSlice slice ); + +/* Inserts a sequence or array into another sequence */ +func SeqInsertSlice(seq *Seq, before_index int, from_arr Arr) { + C.cvSeqInsertSlice((*C.CvSeq)(seq), C.int(before_index), unsafe.Pointer(from_arr)) +} + +// CVAPI(void) cvSeqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); + +/* Sorts sequence in-place given element comparison function */ +func SeqSort(seq *Seq, f CmpFunc, userdata unsafe.Pointer) { + fc := func(a C.CVoid, b C.CVoid, data unsafe.Pointer) int { + return f(unsafe.Pointer(a), unsafe.Pointer(b), data) + } + cmpFunc := C.GoOpenCV_CmpFunc(unsafe.Pointer(&fc)) + C.cvSeqSort((*C.CvSeq)(seq), cmpFunc, unsafe.Pointer(userdata)) +} + +// CVAPI(void) cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata CV_DEFAULT(NULL) ); + +/* Finds element in a [sorted] sequence */ +func SeqSearch(seq *Seq, elem unsafe.Pointer, f CmpFunc, is_sorted int, + lem_idx *int32, userdata unsafe.Pointer) { + fc := func(a C.CVoid, b C.CVoid, userdata Arr) int { + return f(unsafe.Pointer(a), unsafe.Pointer(b), unsafe.Pointer(userdata)) + } + cmpFunc := C.GoOpenCV_CmpFunc(unsafe.Pointer(&fc)) + C.cvSeqSearch((*C.CvSeq)(seq), elem, cmpFunc, + C.int(is_sorted), (*C.int)(lem_idx), userdata) +} + +// CVAPI(schar*) cvSeqSearch( CvSeq* seq, const void* elem, CvCmpFunc func, +// int is_sorted, int* elem_idx, +// void* userdata CV_DEFAULT(NULL) ); + +/* Reverses order of sequence elements in-place */ +func SeqInvert(seq *Seq) { + C.cvSeqInvert((*C.CvSeq)(seq)) +} + +// CVAPI(void) cvSeqInvert( CvSeq* seq ); + +/* Splits sequence into one or more equivalence classes using the specified criteria */ +func SeqPartition(seq *Seq, storage *MemStorage, labels **Seq, + f CmpFunc, userdata unsafe.Pointer) { + fc := func(a C.CVoid, b C.CVoid, userdata Arr) int { + return f(unsafe.Pointer(a), unsafe.Pointer(b), unsafe.Pointer(userdata)) + } + cmpFunc := C.GoOpenCV_CmpFunc(unsafe.Pointer(&fc)) + cvSeq := (*C.CvSeq)(*labels) + C.cvSeqPartition((*C.CvSeq)(seq), (*C.CvMemStorage)(storage), &cvSeq, + cmpFunc, userdata) +} + +// CVAPI(int) cvSeqPartition( const CvSeq* seq, CvMemStorage* storage, +// CvSeq** labels, CvCmpFunc is_equal, void* ); + +/* Inserts a new element in the middle of sequence. + cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */ +func SeqInsert(seq *Seq, before_index int, element unsafe.Pointer) *int8 { + r := C.cvSeqInsert((*C.CvSeq)(seq), C.int(before_index), element) + return (*int8)(r) +} + +// CVAPI(schar*) cvSeqInsert( CvSeq* seq, int before_index, +// const void* element CV_DEFAULT(NULL)); + +/* Removes specified sequence element */ +func SeqRemove(seq *Seq, index int) { + C.cvSeqRemove((*C.CvSeq)(seq), C.int(index)) +} + +// CVAPI(void) cvSeqRemove( CvSeq* seq, int index ); + +/* Changes default size (granularity) of sequence blocks. + The default size is ~1Kbyte */ +func SetSeqBlockSize(seq *Seq, delta_elems int) { + C.cvSetSeqBlockSize((*C.CvSeq)(seq), C.int(delta_elems)) +} + +// CVAPI(void) cvSetSeqBlockSize( CvSeq* seq, int delta_elems ); + +/* Copies sequence content to a continuous piece of memory */ +func CvtSeqToArray(seq *Seq, delta_elems unsafe.Pointer, slice Slice) { + C.cvCvtSeqToArray((*C.CvSeq)(seq), delta_elems, (C.CvSlice)(slice)) +} + +// CVAPI(void*) cvCvtSeqToArray( const CvSeq* seq, void* elements, +// CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) ); + +/* Creates sequence header for array. + After that all the operations on sequences that do not alter the content + can be applied to the resultant sequence */ +func MakeSeqHeaderForArray(seq_type, header_size, elem_size int, + elems unsafe.Pointer, total int, seq *Seq, block *SeqBlock) *Seq { + r := C.cvMakeSeqHeaderForArray(C.int(seq_type), C.int(header_size), + C.int(elem_size), elems, C.int(total), (*C.CvSeq)(seq), + (*C.CvSeqBlock)(block)) + return (*Seq)(r) +} + +// CVAPI(CvSeq*) cvMakeSeqHeaderForArray( int seq_type, int header_size, +// int elem_size, void* elements, int total, +// CvSeq* seq, CvSeqBlock* block ); /****************************************************************************************\ * Drawing * \****************************************************************************************/ +const CV_FILLED = C.CV_FILLED + /* Draws 4-connected, 8-connected or antialiased line segment connecting two points */ //color Scalar, -func Line(image *IplImage, pt1, pt2 Point, color Scalar, thickness, line_type, shift int) { - C.cvLine( - unsafe.Pointer(image), +func Line(image unsafe.Pointer, pt1, pt2 Point, color Scalar, thickness, line_type, shift int) { + C.cvLine(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), ) } -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), - ) -} -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), - ) -} //CVAPI(void) cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, // CvScalar color, int thickness CV_DEFAULT(1), // int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); +/* Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2), + if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn */ +func Rectangle(image unsafe.Pointer, pt1, pt2 Point, color Scalar, thickness, line_type, shift int) { + C.cvRectangle(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), + ) +} + +// CVAPI(void) cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, +// CvScalar color, int thickness CV_DEFAULT(1), +// int line_type CV_DEFAULT(8), +// int shift CV_DEFAULT(0)); + +func Circle(image unsafe.Pointer, pt1 Point, r int, color Scalar, thickness, line_type, shift int) { + C.cvCircle(image, + C.cvPoint(C.int(pt1.X), C.int(pt1.Y)), + C.int(r), + (C.CvScalar)(color), + C.int(thickness), C.int(line_type), C.int(shift), + ) +} + +/* Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector, + depending on , and parameters. The resultant figure + is rotated by . All the angles are in degrees */ +// CVAPI(void) cvEllipse( CvArr* img, CvPoint center, CvSize axes, +// double angle, double start_angle, double end_angle, +// CvScalar color, int thickness CV_DEFAULT(1), +// int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +func Ellipse(image unsafe.Pointer, center Point, axes Size, angle, start_angle, end_angle float64, + color Scalar, thickness, line_type, shift int) { + C.cvEllipse(image, + C.cvPoint(C.int(center.X), C.int(center.Y)), + C.cvSize(C.int(axes.Width), C.int(axes.Height)), C.double(angle), + C.double(start_angle), C.double(end_angle) ,(C.CvScalar)(color), + C.int(thickness), C.int(line_type), C.int(shift), + ) +} + +// CVAPI(void) cvDrawContours( CvArr *img, CvSeq* contour, +// CvScalar external_color, CvScalar hole_color, +// int max_level, int thickness CV_DEFAULT(1), +// int line_type CV_DEFAULT(8), +// CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/* Draws contour outlines or filled interiors on the image */ +func DrawContours(image unsafe.Pointer, contour *Seq, external_color Scalar, + hole_color Scalar, max_level, thickness, line_type int, offset Point) { + C.cvDrawContours(image, + (*C.CvSeq)(contour), + (C.CvScalar)(external_color), + (C.CvScalar)(hole_color), + C.int(max_level), C.int(thickness), C.int(line_type), + C.cvPoint(C.int(offset.X), C.int(offset.Y)), + ) +} + +const ( + CV_FONT_HERSHEY_SIMPLEX = C.CV_FONT_HERSHEY_SIMPLEX + CV_FONT_HERSHEY_PLAIN = C.CV_FONT_HERSHEY_PLAIN + CV_FONT_HERSHEY_DUPLEX = C.CV_FONT_HERSHEY_DUPLEX + CV_FONT_HERSHEY_COMPLEX = C.CV_FONT_HERSHEY_COMPLEX + CV_FONT_HERSHEY_TRIPLEX = C.CV_FONT_HERSHEY_TRIPLEX + CV_FONT_HERSHEY_COMPLEX_SMALL = C.CV_FONT_HERSHEY_COMPLEX_SMALL + CV_FONT_HERSHEY_SCRIPT_SIMPLEX = C.CV_FONT_HERSHEY_SCRIPT_SIMPLEX + CV_FONT_HERSHEY_SCRIPT_COMPLEX = C.CV_FONT_HERSHEY_SCRIPT_COMPLEX +) + +/* Renders text stroke with specified font and color at specified location. + CvFont should be initialized with cvInitFont */ +// CVAPI(void) cvPutText( CvArr* img, const char* text, CvPoint org, +// const CvFont* font, CvScalar color ); +func PutText(image unsafe.Pointer, text string, org Point, font_face int, + hscale, vscale, shear float64, thickness, line_type int, color Scalar){ + // create CvFont sturucture + f := &C.CvFont{} + C.cvInitFont(f, C.int(font_face), C.double(hscale), C.double(vscale), + C.double(shear), C.int(thickness), C.int(line_type)) + C.cvPutText(image, C.CString(text), C.cvPoint(C.int(org.X), C.int(org.Y)), + f, (C.CvScalar)(color)) +} + /****************************************************************************************\ * System functions * \****************************************************************************************/ @@ -577,3 +797,10 @@ func Circle(image *IplImage, pt1 Point, radius int, color Scalar, thickness, lin /****************************************************************************************\ * Data Persistence * \****************************************************************************************/ + +/*********************************** Adding own types ***********************************/ + +/* universal functions */ +func Release(ptr unsafe.Pointer) { C.cvRelease(&ptr) } + +// CVAPI(void) cvRelease( void** struct_ptr ); \ No newline at end of file diff --git a/opencv/cxtype.go b/opencv/cxtype.go index 9fe7603..8258422 100644 --- a/opencv/cxtype.go +++ b/opencv/cxtype.go @@ -1,6 +1,7 @@ // Copyright 2011 . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// 22/11/2013 Updated by . package opencv @@ -54,7 +55,13 @@ static int myGetTermCriteriaType(const CvTermCriteria* x) { return x->type; } +#define CV_CHAIN_SIZE sizeof(CvChain) +#define CV_CONTOUR_SIZE sizeof(CvContour) +#define CV_SEQ_SIZE sizeof(CvSeq) +#define CV_SEQBLOCK_SIZE sizeof(CvSeqBlock) +#define CV_POINT_SIZE sizeof(CvPoint) //----------------------------------------------------------------------------- + */ import "C" import ( @@ -137,7 +144,6 @@ const ( //----------------------------------------------------------------------------- // cxtypes.h //----------------------------------------------------------------------------- - type Arr unsafe.Pointer /*****************************************************************************\ @@ -256,6 +262,9 @@ func (img *IplImage) ImageSize() int { func (img *IplImage) ImageData() unsafe.Pointer { return unsafe.Pointer(img.imageData) } +func (img *IplImage) Ptr() unsafe.Pointer { + return unsafe.Pointer(img) +} type IplROI C.IplROI @@ -320,6 +329,55 @@ const ( * Matrix type (CvMat) * \****************************************************************************************/ +const( +CV_8U = C.CV_8U +CV_8S = C.CV_8S +CV_16U = C.CV_16U +CV_16S = C.CV_16S +CV_32S = C.CV_32S +CV_32F = C.CV_32F +CV_64F = C.CV_64F +CV_USRTYPE1 = C.CV_USRTYPE1 + +CV_MAT_DEPTH_MASK = C.CV_MAT_DEPTH_MASK + +CV_8UC1 = C.CV_8UC1 +CV_8UC2 = C.CV_8UC2 +CV_8UC3 = C.CV_8UC3 +CV_8UC4 = C.CV_8UC4 + +CV_8SC1 = C.CV_8SC1 +CV_8SC2 = C.CV_8SC2 +CV_8SC3 = C.CV_8SC3 +CV_8SC4 = C.CV_8SC4 + +CV_16UC1 = C.CV_16UC1 +CV_16UC2 = C.CV_16UC2 +CV_16UC3 = C.CV_16UC3 +CV_16UC4 = C.CV_16UC4 + +CV_16SC1 = C.CV_16SC1 +CV_16SC2 = C.CV_16SC2 +CV_16SC3 = C.CV_16SC3 +CV_16SC4 = C.CV_16SC4 + +CV_32SC1 = C.CV_32SC1 +CV_32SC2 = C.CV_32SC2 +CV_32SC3 = C.CV_32SC3 +CV_32SC4 = C.CV_32SC4 + +CV_32FC1 = C.CV_32FC1 +CV_32FC2 = C.CV_32FC2 +CV_32FC3 = C.CV_32FC3 +CV_32FC4 = C.CV_32FC4 + +CV_64FC1 = C.CV_64FC1 +CV_64FC2 = C.CV_64FC2 +CV_64FC3 = C.CV_64FC3 +CV_64FC4 = C.CV_64FC4 + +) + type Mat C.CvMat func (mat *Mat) Type() int { @@ -338,6 +396,9 @@ func (mat *Mat) Rows() int { func (mat *Mat) Cols() int { return int(mat.cols) } +func (mat *Mat) Ptr() unsafe.Pointer { + return unsafe.Pointer(mat) +} func CV_IS_MAT_HDR(mat interface{}) bool { return false @@ -552,6 +613,10 @@ func (x *TermCriteria) Epsilon() float64 { /******************************* CvPoint and variants ***********************************/ +const ( + CV_POINT_SIZE = C.CV_POINT_SIZE +) + type Point struct { X int Y int @@ -577,6 +642,11 @@ type Point3D64f struct { Z float64 } +func GetPoint(p unsafe.Pointer) Point { + cvpt := (*C.CvPoint)(p) + return Point{int(cvpt.x), int(cvpt.y)} +} + /******************************** CvSize's & CvBox **************************************/ type Size struct { @@ -601,6 +671,10 @@ type LineIterator C.CvLineIterator type Slice C.CvSlice +var ( + CV_WHOLE_SEQ Slice = (Slice)(C.cvSlice(0, CV_WHOLE_SEQ_END_INDEX)) +) + const ( CV_WHOLE_SEQ_END_INDEX = C.CV_WHOLE_SEQ_END_INDEX ) @@ -629,6 +703,23 @@ func (s Scalar) Val() [4]float64 { } } +// CV_INLINE CvScalar cvScalarAll( double val0123 ); + +func ScalarN(val0, val1, val2, val3 float64) Scalar { + rv := C.cvScalar(C.double(val0), C.double(val1), + C.double(val2), C.double(val3)) + return (Scalar)(rv) +} + +// CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), +// double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)); +func RealScalar(val0 float64) Scalar { + rv := C.cvRealScalar(C.double(val0)) + return (Scalar)(rv) +} + +// CV_INLINE CvScalar cvRealScalar( double val0 ); + /****************************************************************************************\ * Dynamic Data structures * \****************************************************************************************/ @@ -644,6 +735,84 @@ type MemStoragePos C.CvMemStoragePos type SeqBlock C.CvSeqBlock type Seq C.CvSeq +const ( + CV_SEQ_SIZE = C.CV_SEQ_SIZE + CV_SEQBLOCK_SIZE = C.CV_SEQBLOCK_SIZE +) + +func (seq *Seq) Count() int { + return int(seq.total) +} + +func (seq *Seq) Ptr() unsafe.Pointer { + return unsafe.Pointer(seq) +} + +func (seq *Seq) H_next() *Seq { + return (*Seq)(seq.h_next) +} + +func (seq *Seq) H_prev() *Seq { + return (*Seq)(seq.h_prev) +} + +/* +typedef struct CvSeq { + int flags; // miscellaneous flags + int header_size; // size of sequence header + CvSeq* h_prev; // previous sequence + CvSeq* h_next; // next sequence + CvSeq* v_prev; // 2nd previous sequence + CvSeq* v_next // 2nd next sequence + int total; // total number of elements + int elem_size; // size of sequence element in byte + char* block_max; // maximal bound of the last block + char* ptr; // current write pointer + int delta_elems; // how many elements allocated + // when the sequence grows + CvMemStorage* storage; // where the sequence is stored + CvSeqBlock* free_blocks; // free blocks list + CvSeqBlock* first; // pointer to the first sequence block +}*/ + +type CmpFunc func(a unsafe.Pointer, b unsafe.Pointer, userdata unsafe.Pointer) int + +const ( + CV_SEQ_ELTYPE_BITS = C.CV_SEQ_ELTYPE_BITS + CV_SEQ_ELTYPE_MASK = C.CV_SEQ_ELTYPE_MASK + + CV_SEQ_ELTYPE_POINT = C.CV_SEQ_ELTYPE_POINT + CV_SEQ_ELTYPE_CODE = C.CV_SEQ_ELTYPE_CODE + CV_SEQ_ELTYPE_GENERIC = C.CV_SEQ_ELTYPE_GENERIC + CV_SEQ_ELTYPE_PTR = C.CV_SEQ_ELTYPE_PTR + CV_SEQ_ELTYPE_PPOINT = C.CV_SEQ_ELTYPE_PPOINT + CV_SEQ_ELTYPE_INDEX = C.CV_SEQ_ELTYPE_INDEX + CV_SEQ_ELTYPE_GRAPH_EDGE = C.CV_SEQ_ELTYPE_GRAPH_EDGE + CV_SEQ_ELTYPE_GRAPH_VERTEX = C.CV_SEQ_ELTYPE_GRAPH_VERTEX + CV_SEQ_ELTYPE_TRIAN_ATR = C.CV_SEQ_ELTYPE_TRIAN_ATR + CV_SEQ_ELTYPE_CONNECTED_COMP = C.CV_SEQ_ELTYPE_CONNECTED_COMP + CV_SEQ_ELTYPE_POINT3D = C.CV_SEQ_ELTYPE_POINT3D + CV_SEQ_KIND_BITS = C.CV_SEQ_KIND_BITS + CV_SEQ_KIND_MASK = C.CV_SEQ_KIND_MASK + + /* types of sequences */ + CV_SEQ_KIND_GENERIC = C.CV_SEQ_KIND_GENERIC + CV_SEQ_KIND_CURVE = C.CV_SEQ_KIND_CURVE + CV_SEQ_KIND_BIN_TREE = C.CV_SEQ_KIND_BIN_TREE + + /* types of sparse sequences (sets) */ + CV_SEQ_KIND_GRAPH = C.CV_SEQ_KIND_GRAPH + CV_SEQ_KIND_SUBDIV2D = C.CV_SEQ_KIND_SUBDIV2D + + CV_SEQ_FLAG_SHIFT = C.CV_SEQ_FLAG_SHIFT + + /* flags for curves */ + CV_SEQ_FLAG_CLOSED = C.CV_SEQ_FLAG_CLOSED + CV_SEQ_FLAG_SIMPLE = C.CV_SEQ_FLAG_SIMPLE + CV_SEQ_FLAG_CONVEX = C.CV_SEQ_FLAG_CONVEX + CV_SEQ_FLAG_HOLE = C.CV_SEQ_FLAG_HOLE +) + /*************************************** Set ********************************************/ type Set C.CvSet @@ -661,6 +830,11 @@ type Graph C.CvGraph type Chain C.CvChain type Contour C.CvContour +const ( + CV_CHAIN_SIZE = C.CV_CHAIN_SIZE + CV_CONTOUR_SIZE = C.CV_CONTOUR_SIZE +) + /****************************************************************************************\ * Sequence types * \****************************************************************************************/ diff --git a/opencv/imgproc.go b/opencv/imgproc.go index 90ebb5c..4fdc744 100644 --- a/opencv/imgproc.go +++ b/opencv/imgproc.go @@ -1,7 +1,10 @@ -// Copyright 2013 jrweizhang AT gmail.com. All rights reserved. +// Copyright 2014 . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Merged with contributions by jrweizhang AT gmail.com. + +// Bindings for Intel's OpenCV computer vision library. package opencv //#include "opencv.h" @@ -10,20 +13,107 @@ package opencv //#cgo freebsd pkg-config: opencv //#cgo windows LDFLAGS: -lopencv_core242.dll -lopencv_imgproc242.dll -lopencv_photo242.dll -lopencv_highgui242.dll -lstdc++ import "C" + import ( //"errors" - //"log" "unsafe" ) -const ( - CV_INTER_NN = int(C.CV_INTER_NN) - CV_INTER_LINEAR = int(C.CV_INTER_LINEAR) - CV_INTER_CUBIC = int(C.CV_INTER_CUBIC) - CV_INTER_AREA = int(C.CV_INTER_AREA) - CV_INTER_LANCZOS4 = int(C.CV_INTER_LANCZOS4) -) +/*********************** Background statistics accumulation *****************************/ +/****************************************************************************************\ +* Image Processing * +\****************************************************************************************/ + +/* creates structuring element used for morphological operations +CVAPI(IplConvKernel*) cvCreateStructuringElementEx( + int cols, int rows, int anchor_x, int anchor_y, + int shape, int* values CV_DEFAULT(NULL) );*/ +func CreateStructuringElementEx(cols, rows, anchor_x, anchor_y, + shape int, values *int32) *IplConvKernel{ + kernel := C.cvCreateStructuringElementEx(C.int(cols), C.int(rows), + C.int(anchor_x), C.int(anchor_y), C.int(shape), + (*C.int)(values)) + return (*IplConvKernel)(kernel) +} + +/* releases structuring element +CVAPI(void) cvReleaseStructuringElement( IplConvKernel** element );*/ +func ReleaseStructuringElement(kernel *IplConvKernel){ + k := (*C.IplConvKernel)(kernel) + C.cvReleaseStructuringElement(&k) +} + +/* erodes input image (applies minimum filter) one or more times. + If element pointer is NULL, 3x3 rectangular element is used +CVAPI(void) cvErode( const CvArr* src, CvArr* dst, + IplConvKernel* element CV_DEFAULT(NULL), + int iterations CV_DEFAULT(1) );*/ +func Erode(src, dst unsafe.Pointer, kernel *IplConvKernel, + iterations int){ + C.cvErode(src, dst, (*C.IplConvKernel)(kernel), C.int(iterations)) +} + +/* dilates input image (applies maximum filter) one or more times. + If element pointer is NULL, 3x3 rectangular element is used +CVAPI(void) cvDilate( const CvArr* src, CvArr* dst, + IplConvKernel* element CV_DEFAULT(NULL), + int iterations CV_DEFAULT(1) );*/ +func Dilate(src, dst unsafe.Pointer, kernel *IplConvKernel, + iterations int){ + C.cvDilate(src, dst, (*C.IplConvKernel)(kernel), C.int(iterations)) +} + +/* Performs complex morphological transformation +CVAPI(void) cvMorphologyEx( const CvArr* src, CvArr* dst, + CvArr* temp, IplConvKernel* element, + int operation, int iterations CV_DEFAULT(1) );*/ +func MorphologyEx(src, dst, temp unsafe.Pointer, kernel *IplConvKernel, + operation, iterations int){ + C.cvMorphologyEx(src, dst, temp, (*C.IplConvKernel)(kernel), + C.int(operation), C.int(iterations)) +} + +/* Calculates all spatial and central moments up to the 3rd order +CVAPI(void) cvMoments( const CvArr* arr, CvMoments* moments, int binary CV_DEFAULT(0));*/ +func GetMoments(arr unsafe.Pointer, moms *Moments, binary int){ + C.cvMoments(arr, (*C.CvMoments)(moms), C.int(binary)) +} + +/* Retrieve particular spatial, central or normalized central moments */ + +/*CVAPI(double) cvGetSpatialMoment( CvMoments* moments, int x_order, int y_order );*/ +func GetSpatialMoment(moms *Moments, x_order, y_order int) float64{ + value := C.cvGetSpatialMoment((*C.CvMoments)(moms), + C.int(x_order), C.int(y_order)) + return float64(value) +} + +/*CVAPI(double) cvGetCentralMoment( CvMoments* moments, int x_order, int y_order );*/ +func GetCentralMoment(moms *Moments, x_order, y_order int) float64{ + value := C.cvGetCentralMoment((*C.CvMoments)(moms), + C.int(x_order), C.int(y_order)) + return float64(value) +} + +/*CVAPI(double) cvGetNormalizedCentralMoment( CvMoments* moments, + int x_order, int y_order );*/ +func GetNormalizedCentralMoment(moms *Moments, x_order, y_order int) float64{ + value := C.cvGetNormalizedCentralMoment((*C.CvMoments)(moms), + C.int(x_order), C.int(y_order)) + return float64(value) +} + +/* Calculates 7 Hu's invariants from precalculated spatial and central moments*/ + +/*CVAPI(void) cvGetHuMoments( CvMoments* moments, CvHuMoments* hu_moments );*/ +func GetHuMoments(moms *Moments, hu_moms *HuMoments){ + C.cvGetHuMoments((*C.CvMoments)(moms), + (*C.CvHuMoments)(hu_moms)) +} + +/* CVAPI(void) cvResize( const CvArr* src, CvArr* dst, + int interpolation CV_DEFAULT( CV_INTER_LINEAR ));*/ func Resize(src *IplImage, width, height, interpolation int) *IplImage { if width == 0 && height == 0 { panic("Width and Height cannot be 0 at the same time") @@ -47,8 +137,162 @@ func Crop(src *IplImage, x, y, width, height int) *IplImage { src.SetROI(rect) dest := CreateImage(width, height, src.Depth(), src.Channels()) - Copy(src, dest, nil) + Copy(src.Ptr(), dest.Ptr(), nil) src.ResetROI() return dest } + +/*********************************** data sampling **************************************/ + +/****************************************************************************************\ +* Contours retrieving * +\****************************************************************************************/ + +/* Retrieves outer and optionally inner boundaries of white (non-zero) connected + components in the black (zero) background + Default Value: header_size = sizeof(CvContour), + mode = CV_RETR_LIST, + method = CV_CHAIN_APPROX_SIMPLE, + offset = cvPoint(0,0))*/ +func FindContours(image unsafe.Pointer, storage *MemStorage, first_contour **Seq, + header_size int, mode int, method int, offset Point) int { + cvSeq := (*C.CvSeq)(*first_contour) + r := C.cvFindContours(image, (*C.CvMemStorage)(storage), + &cvSeq, C.int(header_size), C.int(mode), C.int(method), + C.cvPoint(C.int(offset.X), C.int(offset.Y))) + (*first_contour) = (*Seq)(cvSeq) + return int(r) +} + +// CVAPI(int) cvFindContours( CvArr* image, CvMemStorage* storage, CvSeq** first_contour, +// int header_size CV_DEFAULT(sizeof(CvContour)), +// int mode CV_DEFAULT(CV_RETR_LIST), +// int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), +// CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/* Initalizes contour retrieving process. + Calls cvStartFindContours. + Calls cvFindNextContour until null pointer is returned + or some other condition becomes true. + Calls cvEndFindContours at the end. */ +func StartFindContours(image unsafe.Pointer, storage *MemStorage, + header_size int, mode int, method int, offset Point) *ContourScanner { + scanner := C.cvStartFindContours(image, (*C.CvMemStorage)(storage), + C.int(header_size), C.int(mode), C.int(method), + C.cvPoint(C.int(offset.X), C.int(offset.Y))) + return (*ContourScanner)(&scanner) +} + +// CVAPI(CvContourScanner) cvStartFindContours( CvArr* image, CvMemStorage* storage, +// int header_size CV_DEFAULT(sizeof(CvContour)), +// int mode CV_DEFAULT(CV_RETR_LIST), +// int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), +// CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/* Retrieves next contour */ +func FindNextContour(scanner *ContourScanner) *Seq { + r := C.cvFindNextContour(C.CvContourScanner(*scanner)) + return (*Seq)(r) +} + +// CVAPI(CvSeq*) cvFindNextContour( CvContourScanner scanner ); + +/* Substitutes the last retrieved contour with the new one + (if the substitutor is null, the last retrieved contour is removed from the tree) */ +func SubstituteContour(scanner *ContourScanner, new_contour *Seq) { + C.cvSubstituteContour(C.CvContourScanner(*scanner), (*C.CvSeq)(new_contour)) +} + +// CVAPI(void) cvSubstituteContour( CvContourScanner scanner, CvSeq* new_contour ); + +/* Releases contour scanner and returns pointer to the first outer contour */ +func EndFindContours(scanner *ContourScanner) *Seq { + r := C.cvEndFindContours((*C.CvContourScanner)(scanner)) + return (*Seq)(r) +} + +// CVAPI(CvSeq*) cvEndFindContours( CvContourScanner* scanner ); + +/* Approximates a single Freeman chain or a tree of chains to polygonal curves */ +func ApproxChains(src_seq *Seq, storage *MemStorage, method int, parameter float64, + minimal_perimeter int, recursive int) *Seq { + r := C.cvApproxChains((*C.CvSeq)(src_seq), (*C.CvMemStorage)(storage), C.int(method), + C.double(parameter), C.int(minimal_perimeter), C.int(recursive)) + return (*Seq)(r) +} + +// CVAPI(CvSeq*) cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, +// int method CV_DEFAULT(CV_CHAIN_APPROX_SIMPLE), +// double parameter CV_DEFAULT(0), +// int minimal_perimeter CV_DEFAULT(0), +// int recursive CV_DEFAULT(0)); + +/* Initalizes Freeman chain reader. + The reader is used to iteratively get coordinates of all the chain points. + If the Freeman codes should be read as is, a simple sequence reader should be used */ +func StartReadChainPoints(chain *Chain, reader *ChainPtReader) { + C.cvStartReadChainPoints((*C.CvChain)(chain), (*C.CvChainPtReader)(reader)) +} + +// CVAPI(void) cvStartReadChainPoints( CvChain* chain, CvChainPtReader* reader ); + +/* Retrieves the next chain point */ +func ReadChainPoint(reader *ChainPtReader) *Point { + r := C.cvReadChainPoint((*C.CvChainPtReader)(reader)) + p := &Point{int(r.x), int(r.y)} + return p +} + +// CVAPI(CvPoint) cvReadChainPoint( CvChainPtReader* reader ); + +/****************************************************************************************\ +* Contour Processing and Shape Analysis * +\****************************************************************************************/ + +/* Calculates perimeter of a contour*/ +func ContourPerimeter(seq unsafe.Pointer) float64 { + r := C.cvContourPerimeter(seq) + return (float64)(r) +} + +// CV_INLINE double cvContourPerimeter( const void* contour ) +// { +// return cvArcLength( contour, CV_WHOLE_SEQ, 1 ); +// } + +/* Approximates a single polygonal curve (contour) or + a tree of polygonal curves (contours) + Default Values: recursive = 0*/ +func ApproxPoly(src_seq unsafe.Pointer, header_size int, storage *MemStorage, + method int, eps float64, recursive int) *Seq { + r := C.cvApproxPoly(src_seq, C.int(header_size), (*C.CvMemStorage)(storage), + C.int(method), C.double(eps), C.int(recursive)) + return (*Seq)(r) +} + +// CVAPI(CvSeq*) cvApproxPoly( const void* src_seq, +// int header_size, CvMemStorage* storage, +// int method, double eps, +// int recursive CV_DEFAULT(0)); + +/****************************************************************************************\ +* Histogram functions * +\****************************************************************************************/ + +/* Applies fixed-level threshold to grayscale image. + This is a basic operation applied before retrieving contours */ +func Threshold(src unsafe.Pointer, dst unsafe.Pointer, + threshold, max_value float64, threshold_type int) float64 { + r := C.cvThreshold(src, dst, C.double(threshold), + C.double(max_value), C.int(threshold_type)) + return float64(r) +} + +// CVAPI(double) cvThreshold( const CvArr* src, CvArr* dst, +// double threshold, double max_value, +// int threshold_type ); + +/****************************************************************************************\ +* Feature detection * +\****************************************************************************************/ diff --git a/opencv/imgptype.go b/opencv/imgptype.go new file mode 100644 index 0000000..5a985bd --- /dev/null +++ b/opencv/imgptype.go @@ -0,0 +1,574 @@ +// Copyright 2014 . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Bindings for Intel's OpenCV computer vision library. +package opencv + +//#include "opencv.h" +//#cgo linux pkg-config: opencv +//#cgo darwin pkg-config: opencv +//#cgo freebsd pkg-config: opencv +//#cgo windows LDFLAGS: -lopencv_core242.dll -lopencv_imgproc242.dll -lopencv_photo242.dll -lopencv_highgui242.dll -lstdc++ +import "C" + +/* Connected component structure */ +type ConnectedComp C.CvConnectedComp + +/* +// { +// double area; area of the connected component +// CvScalar value; average color of the connected component +// CvRect rect; ROI of the component +// CvSeq* contour; optional component boundary +// (the contour might have child contours corresponding to the holes) +// } +*/ + +// /* Image smooth methods */ +const ( + CV_BLUR_NO_SCALE = C.CV_BLUR_NO_SCALE + CV_BLUR = C.CV_BLUR + CV_GAUSSIAN = C.CV_GAUSSIAN + CV_MEDIAN = C.CV_MEDIAN + CV_BILATERAL = C.CV_BILATERAL +) + +// /* Filters used in pyramid decomposition */ +const ( + CV_GAUSSIAN_5x5 = C.CV_GAUSSIAN_5x5 +) + +// /* Special filters */ +const ( + CV_SCHARR = C.CV_SCHARR + CV_MAX_SOBEL_KSIZE = C.CV_MAX_SOBEL_KSIZE +) + +// /* Constants for color conversion */ +const ( + CV_BGR2BGRA = C.CV_BGR2BGRA + CV_RGB2RGBA = C.CV_RGB2RGBA + + CV_BGRA2BGR = C.CV_BGRA2BGR + CV_RGBA2RGB = C.CV_RGBA2RGB + + CV_BGR2RGBA = C.CV_BGR2RGBA + CV_RGB2BGRA = C.CV_RGB2BGRA + + CV_RGBA2BGR = C.CV_RGBA2BGR + CV_BGRA2RGB = C.CV_BGRA2RGB + + CV_BGR2RGB = C.CV_BGR2RGB + CV_RGB2BGR = C.CV_RGB2BGR + + CV_BGRA2RGBA = C.CV_BGRA2RGBA + CV_RGBA2BGRA = C.CV_RGBA2BGRA + + CV_BGR2GRAY = C.CV_BGR2GRAY + CV_RGB2GRAY = C.CV_RGB2GRAY + CV_GRAY2BGR = C.CV_GRAY2BGR + CV_GRAY2RGB = C.CV_GRAY2RGB + CV_GRAY2BGRA = C.CV_GRAY2BGRA + CV_GRAY2RGBA = C.CV_GRAY2RGBA + CV_BGRA2GRAY = C.CV_BGRA2GRAY + CV_RGBA2GRAY = C.CV_RGBA2GRAY + + CV_BGR2BGR565 = C.CV_BGR2BGR565 + CV_RGB2BGR565 = C.CV_RGB2BGR565 + CV_BGR5652BGR = C.CV_BGR5652BGR + CV_BGR5652RGB = C.CV_BGR5652RGB + CV_BGRA2BGR565 = C.CV_BGRA2BGR565 + CV_RGBA2BGR565 = C.CV_RGBA2BGR565 + CV_BGR5652BGRA = C.CV_BGR5652BGRA + CV_BGR5652RGBA = C.CV_BGR5652RGBA + + CV_GRAY2BGR565 = C.CV_GRAY2BGR565 + CV_BGR5652GRAY = C.CV_BGR5652GRAY + + CV_BGR2BGR555 = C.CV_BGR2BGR555 + CV_RGB2BGR555 = C.CV_RGB2BGR555 + CV_BGR5552BGR = C.CV_BGR5552BGR + CV_BGR5552RGB = C.CV_BGR5552RGB + CV_BGRA2BGR555 = C.CV_BGRA2BGR555 + CV_RGBA2BGR555 = C.CV_RGBA2BGR555 + CV_BGR5552BGRA = C.CV_BGR5552BGRA + CV_BGR5552RGBA = C.CV_BGR5552RGBA + + CV_GRAY2BGR555 = C.CV_GRAY2BGR555 + CV_BGR5552GRAY = C.CV_BGR5552GRAY + + CV_BGR2XYZ = C.CV_BGR2XYZ + CV_RGB2XYZ = C.CV_RGB2XYZ + CV_XYZ2BGR = C.CV_XYZ2BGR + CV_XYZ2RGB = C.CV_XYZ2RGB + + CV_BGR2YCrCb = C.CV_BGR2YCrCb + CV_RGB2YCrCb = C.CV_RGB2YCrCb + CV_YCrCb2BGR = C.CV_YCrCb2BGR + CV_YCrCb2RGB = C.CV_YCrCb2RGB + + CV_BGR2HSV = C.CV_BGR2HSV + CV_RGB2HSV = C.CV_RGB2HSV + + CV_BGR2Lab = C.CV_BGR2Lab + CV_RGB2Lab = C.CV_RGB2Lab + + CV_BayerBG2BGR = C.CV_BayerBG2BGR + CV_BayerGB2BGR = C.CV_BayerGB2BGR + CV_BayerRG2BGR = C.CV_BayerRG2BGR + CV_BayerGR2BGR = C.CV_BayerGR2BGR + + CV_BayerBG2RGB = C.CV_BayerBG2RGB + CV_BayerGB2RGB = C.CV_BayerGB2RGB + CV_BayerRG2RGB = C.CV_BayerRG2RGB + CV_BayerGR2RGB = C.CV_BayerGR2RGB + + CV_BGR2Luv = C.CV_BGR2Luv + CV_RGB2Luv = C.CV_RGB2Luv + CV_BGR2HLS = C.CV_BGR2HLS + CV_RGB2HLS = C.CV_RGB2HLS + + CV_HSV2BGR = C.CV_HSV2BGR + CV_HSV2RGB = C.CV_HSV2RGB + + CV_Lab2BGR = C.CV_Lab2BGR + CV_Lab2RGB = C.CV_Lab2RGB + CV_Luv2BGR = C.CV_Luv2BGR + CV_Luv2RGB = C.CV_Luv2RGB + CV_HLS2BGR = C.CV_HLS2BGR + CV_HLS2RGB = C.CV_HLS2RGB + + CV_BayerBG2BGR_VNG = C.CV_BayerBG2BGR_VNG + CV_BayerGB2BGR_VNG = C.CV_BayerGB2BGR_VNG + CV_BayerRG2BGR_VNG = C.CV_BayerRG2BGR_VNG + // CV_BayerGR2BGR_VNG =65, + + // CV_BayerBG2RGB_VNG =CV_BayerRG2BGR_VNG, + // CV_BayerGB2RGB_VNG =CV_BayerGR2BGR_VNG, + // CV_BayerRG2RGB_VNG =CV_BayerBG2BGR_VNG, + // CV_BayerGR2RGB_VNG =CV_BayerGB2BGR_VNG, + + // CV_BGR2HSV_FULL = 66, + // CV_RGB2HSV_FULL = 67, + // CV_BGR2HLS_FULL = 68, + // CV_RGB2HLS_FULL = 69, + + // CV_HSV2BGR_FULL = 70, + // CV_HSV2RGB_FULL = 71, + // CV_HLS2BGR_FULL = 72, + // CV_HLS2RGB_FULL = 73, + + // CV_LBGR2Lab = 74, + // CV_LRGB2Lab = 75, + // CV_LBGR2Luv = 76, + // CV_LRGB2Luv = 77, + + // CV_Lab2LBGR = 78, + // CV_Lab2LRGB = 79, + // CV_Luv2LBGR = 80, + // CV_Luv2LRGB = 81, + + // CV_BGR2YUV = 82, + // CV_RGB2YUV = 83, + // CV_YUV2BGR = 84, + // CV_YUV2RGB = 85, + + // CV_BayerBG2GRAY = 86, + // CV_BayerGB2GRAY = 87, + // CV_BayerRG2GRAY = 88, + // CV_BayerGR2GRAY = 89, + + // //YUV 4:2:0 formats family + // CV_YUV2RGB_NV12 = 90, + // CV_YUV2BGR_NV12 = 91, + // CV_YUV2RGB_NV21 = 92, + // CV_YUV2BGR_NV21 = 93, + // CV_YUV420sp2RGB = CV_YUV2RGB_NV21, + // CV_YUV420sp2BGR = CV_YUV2BGR_NV21, + + // CV_YUV2RGBA_NV12 = 94, + // CV_YUV2BGRA_NV12 = 95, + // CV_YUV2RGBA_NV21 = 96, + // CV_YUV2BGRA_NV21 = 97, + // CV_YUV420sp2RGBA = CV_YUV2RGBA_NV21, + // CV_YUV420sp2BGRA = CV_YUV2BGRA_NV21, + + // CV_YUV2RGB_YV12 = 98, + // CV_YUV2BGR_YV12 = 99, + // CV_YUV2RGB_IYUV = 100, + // CV_YUV2BGR_IYUV = 101, + // CV_YUV2RGB_I420 = CV_YUV2RGB_IYUV, + // CV_YUV2BGR_I420 = CV_YUV2BGR_IYUV, + // CV_YUV420p2RGB = CV_YUV2RGB_YV12, + // CV_YUV420p2BGR = CV_YUV2BGR_YV12, + + // CV_YUV2RGBA_YV12 = 102, + // CV_YUV2BGRA_YV12 = 103, + // CV_YUV2RGBA_IYUV = 104, + // CV_YUV2BGRA_IYUV = 105, + // CV_YUV2RGBA_I420 = CV_YUV2RGBA_IYUV, + // CV_YUV2BGRA_I420 = CV_YUV2BGRA_IYUV, + // CV_YUV420p2RGBA = CV_YUV2RGBA_YV12, + // CV_YUV420p2BGRA = CV_YUV2BGRA_YV12, + + // CV_YUV2GRAY_420 = 106, + // CV_YUV2GRAY_NV21 = CV_YUV2GRAY_420, + // CV_YUV2GRAY_NV12 = CV_YUV2GRAY_420, + // CV_YUV2GRAY_YV12 = CV_YUV2GRAY_420, + // CV_YUV2GRAY_IYUV = CV_YUV2GRAY_420, + // CV_YUV2GRAY_I420 = CV_YUV2GRAY_420, + // CV_YUV420sp2GRAY = CV_YUV2GRAY_420, + // CV_YUV420p2GRAY = CV_YUV2GRAY_420, + + // //YUV 4:2:2 formats family + // CV_YUV2RGB_UYVY = 107, + // CV_YUV2BGR_UYVY = 108, + // //CV_YUV2RGB_VYUY = 109, + // //CV_YUV2BGR_VYUY = 110, + // CV_YUV2RGB_Y422 = CV_YUV2RGB_UYVY, + // CV_YUV2BGR_Y422 = CV_YUV2BGR_UYVY, + // CV_YUV2RGB_UYNV = CV_YUV2RGB_UYVY, + // CV_YUV2BGR_UYNV = CV_YUV2BGR_UYVY, + + // CV_YUV2RGBA_UYVY = 111, + // CV_YUV2BGRA_UYVY = 112, + // //CV_YUV2RGBA_VYUY = 113, + // //CV_YUV2BGRA_VYUY = 114, + // CV_YUV2RGBA_Y422 = CV_YUV2RGBA_UYVY, + // CV_YUV2BGRA_Y422 = CV_YUV2BGRA_UYVY, + // CV_YUV2RGBA_UYNV = CV_YUV2RGBA_UYVY, + // CV_YUV2BGRA_UYNV = CV_YUV2BGRA_UYVY, + + // CV_YUV2RGB_YUY2 = 115, + // CV_YUV2BGR_YUY2 = 116, + // CV_YUV2RGB_YVYU = 117, + // CV_YUV2BGR_YVYU = 118, + // CV_YUV2RGB_YUYV = CV_YUV2RGB_YUY2, + // CV_YUV2BGR_YUYV = CV_YUV2BGR_YUY2, + // CV_YUV2RGB_YUNV = CV_YUV2RGB_YUY2, + // CV_YUV2BGR_YUNV = CV_YUV2BGR_YUY2, + + // CV_YUV2RGBA_YUY2 = 119, + // CV_YUV2BGRA_YUY2 = 120, + // CV_YUV2RGBA_YVYU = 121, + // CV_YUV2BGRA_YVYU = 122, + // CV_YUV2RGBA_YUYV = CV_YUV2RGBA_YUY2, + // CV_YUV2BGRA_YUYV = CV_YUV2BGRA_YUY2, + // CV_YUV2RGBA_YUNV = CV_YUV2RGBA_YUY2, + // CV_YUV2BGRA_YUNV = CV_YUV2BGRA_YUY2, + + // CV_YUV2GRAY_UYVY = 123, + // CV_YUV2GRAY_YUY2 = 124, + // //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY, + // CV_YUV2GRAY_Y422 = CV_YUV2GRAY_UYVY, + // CV_YUV2GRAY_UYNV = CV_YUV2GRAY_UYVY, + // CV_YUV2GRAY_YVYU = CV_YUV2GRAY_YUY2, + // CV_YUV2GRAY_YUYV = CV_YUV2GRAY_YUY2, + // CV_YUV2GRAY_YUNV = CV_YUV2GRAY_YUY2, + + // // alpha premultiplication + // CV_RGBA2mRGBA = 125, + // CV_mRGBA2RGBA = 126, + + // CV_COLORCVT_MAX = 127 +) + +// /* Sub-pixel interpolation methods */ +const ( + CV_INTER_NN = C.CV_INTER_NN + CV_INTER_LINEAR = C.CV_INTER_LINEAR + CV_INTER_CUBIC = C.CV_INTER_CUBIC + CV_INTER_AREA = C.CV_INTER_AREA + CV_INTER_LANCZOS4 = C.CV_INTER_LANCZOS4 +) + +// /* ... and other image warping flags */ +const ( + CV_WARP_FILL_OUTLIERS = C.CV_WARP_FILL_OUTLIERS + CV_WARP_INVERSE_MAP = C.CV_WARP_INVERSE_MAP +) + +// /* Shapes of a structuring element for morphological operations */ +const ( + CV_SHAPE_RECT = C.CV_SHAPE_RECT + CV_SHAPE_CROSS = C.CV_SHAPE_CROSS + CV_SHAPE_ELLIPSE = C.CV_SHAPE_ELLIPSE + CV_SHAPE_CUSTOM = C.CV_SHAPE_CUSTOM +) + +// /* Morphological operations */ +const ( + CV_MOP_ERODE = C.CV_MOP_ERODE + CV_MOP_DILATE = C.CV_MOP_DILATE + CV_MOP_OPEN = C.CV_MOP_OPEN + CV_MOP_CLOSE = C.CV_MOP_CLOSE + CV_MOP_GRADIENT = C.CV_MOP_GRADIENT + CV_MOP_TOPHAT = C.CV_MOP_TOPHAT + CV_MOP_BLACKHAT = C.CV_MOP_BLACKHAT +) + +// /* Spatial and central moments */ +type Moments C.CvMoments + +// typedef struct CvMoments +// { +// double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; /* spatial moments */ +// double mu20, mu11, mu02, mu30, mu21, mu12, mu03; /* central moments */ +// double inv_sqrt_m00; /* m00 != 0 ? 1/sqrt(m00) : 0 */ +// } + +// /* Hu invariants */ +type HuMoments C.CvHuMoments + +// typedef struct CvHuMoments +// { +// double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /* Hu invariants */ +// } + +// /* Template matching methods */ +const ( + CV_TM_SQDIFF = C.CV_TM_SQDIFF + CV_TM_SQDIFF_NORMED = C.CV_TM_SQDIFF_NORMED + CV_TM_CCORR = C.CV_TM_CCORR + CV_TM_CCORR_NORMED = C.CV_TM_CCORR_NORMED + CV_TM_CCOEFF = C.CV_TM_CCOEFF + CV_TM_CCOEFF_NORMED = C.CV_TM_CCOEFF_NORMED +) + +// typedef float (CV_CDECL * CvDistanceFunction)( const float* a, const float* b, void* user_param ); + +/* Contour retrieval modes */ +const ( + CV_RETR_EXTERNAL = C.CV_RETR_EXTERNAL + CV_RETR_LIST = C.CV_RETR_LIST + CV_RETR_CCOMP = C.CV_RETR_CCOMP + CV_RETR_TREE = C.CV_RETR_TREE + CV_RETR_FLOODFILL = C.CV_RETR_FLOODFILL +) + +// /* Contour approximation methods */ +const ( + CV_CHAIN_CODE = C.CV_CHAIN_CODE + CV_CHAIN_APPROX_NONE = C.CV_CHAIN_APPROX_NONE + CV_CHAIN_APPROX_SIMPLE = C.CV_CHAIN_APPROX_SIMPLE + CV_CHAIN_APPROX_TC89_L1 = C.CV_CHAIN_APPROX_TC89_L1 + CV_CHAIN_APPROX_TC89_KCOS = C.CV_CHAIN_APPROX_TC89_KCOS + CV_LINK_RUNS = C.CV_LINK_RUNS +) + +// /* +// Internal structure that is used for sequental retrieving contours from the image. +// It supports both hierarchical and plane variants of Suzuki algorithm. +// */ +type ContourScanner C.CvContourScanner + +// typedef struct _CvContourScanner* CvContourScanner; + +// /* Freeman chain reader state */ +type ChainPtReader C.CvChainPtReader + +// typedef struct CvChainPtReader +// { +// CV_SEQ_READER_FIELDS() +// char code; +// CvPoint pt; +// schar deltas[8][2]; +// } +// CvChainPtReader; + +// /* initializes 8-element array for fast access to 3x3 neighborhood of a pixel */ +// #define CV_INIT_3X3_DELTAS( deltas, step, nch ) \ +// ((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \ +// (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \ +// (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \ +// (deltas)[6] = (step), (deltas)[7] = (step) + (nch)) + +// /****************************************************************************************\ +// * Planar subdivisions * +// \****************************************************************************************/ + +// typedef size_t CvSubdiv2DEdge; + +// #define CV_QUADEDGE2D_FIELDS() \ +// int flags; \ +// struct CvSubdiv2DPoint* pt[4]; \ +// CvSubdiv2DEdge next[4]; + +// #define CV_SUBDIV2D_POINT_FIELDS()\ +// int flags; \ +// CvSubdiv2DEdge first; \ +// CvPoint2D32f pt; \ +// int id; + +// #define CV_SUBDIV2D_VIRTUAL_POINT_FLAG (1 << 30) +type QuadEdge2D C.CvQuadEdge2D + +// typedef struct CvQuadEdge2D +// { +// CV_QUADEDGE2D_FIELDS() +// } +// CvQuadEdge2D; + +type Subdiv2DPoint C.CvSubdiv2DPoint + +// typedef struct CvSubdiv2DPoint +// { +// CV_SUBDIV2D_POINT_FIELDS() +// } +// CvSubdiv2DPoint; + +// #define CV_SUBDIV2D_FIELDS() \ +// CV_GRAPH_FIELDS() \ +// int quad_edges; \ +// int is_geometry_valid; \ +// CvSubdiv2DEdge recent_edge; \ +// CvPoint2D32f topleft; \ +// CvPoint2D32f bottomright; + +// typedef struct CvSubdiv2D +// { +// CV_SUBDIV2D_FIELDS() +// } +// CvSubdiv2D; + +// typedef enum CvSubdiv2DPointLocation +// { +// CV_PTLOC_ERROR = -2, +// CV_PTLOC_OUTSIDE_RECT = -1, +// CV_PTLOC_INSIDE = 0, +// CV_PTLOC_VERTEX = 1, +// CV_PTLOC_ON_EDGE = 2 +// } +// CvSubdiv2DPointLocation; + +// typedef enum CvNextEdgeType +// { +// CV_NEXT_AROUND_ORG = 0x00, +// CV_NEXT_AROUND_DST = 0x22, +// CV_PREV_AROUND_ORG = 0x11, +// CV_PREV_AROUND_DST = 0x33, +// CV_NEXT_AROUND_LEFT = 0x13, +// CV_NEXT_AROUND_RIGHT = 0x31, +// CV_PREV_AROUND_LEFT = 0x20, +// CV_PREV_AROUND_RIGHT = 0x02 +// } +// CvNextEdgeType; + +// /* get the next edge with the same origin point (counterwise) */ +// #define CV_SUBDIV2D_NEXT_EDGE( edge ) (((CvQuadEdge2D*)((edge) & ~3))->next[(edge)&3]) + +// /* Contour approximation algorithms */ +const ( + CV_POLY_APPROX_DP = C.CV_POLY_APPROX_DP +) + +// /* Shape matching methods */ +const ( + CV_CONTOURS_MATCH_I1 = C.CV_CONTOURS_MATCH_I1 + CV_CONTOURS_MATCH_I2 = C.CV_CONTOURS_MATCH_I2 + CV_CONTOURS_MATCH_I3 = C.CV_CONTOURS_MATCH_I3 +) + +// /* Shape orientation */ +const ( + CV_CLOCKWISE = C.CV_CLOCKWISE + CV_COUNTER_CLOCKWISE = C.CV_COUNTER_CLOCKWISE +) + +// /* Convexity defect */ +// typedef struct CvConvexityDefect +// { +// CvPoint* start; /* point of the contour where the defect begins */ +// CvPoint* end; /* point of the contour where the defect ends */ +// CvPoint* depth_point; /* the farthest from the convex hull point within the defect */ +// float depth; /* distance between the farthest point and the convex hull */ +// } CvConvexityDefect; + +// /* Histogram comparison methods */ +const ( + CV_COMP_CORREL = C.CV_COMP_CORREL + CV_COMP_CHISQR = C.CV_COMP_CHISQR + CV_COMP_INTERSECT = C.CV_COMP_INTERSECT + CV_COMP_BHATTACHARYYA = C.CV_COMP_BHATTACHARYYA + CV_COMP_HELLINGER = C.CV_COMP_HELLINGER +) + +// /* Mask size for distance transform */ +// enum +// { +// CV_DIST_MASK_3 =3, +// CV_DIST_MASK_5 =5, +// CV_DIST_MASK_PRECISE =0 +// }; + +// /* Content of output label array: connected components or pixels */ +// enum +// { +// CV_DIST_LABEL_CCOMP = 0, +// CV_DIST_LABEL_PIXEL = 1 +// }; + +// /* Distance types for Distance Transform and M-estimators */ +// enum +// { +// CV_DIST_USER =-1, /* User defined distance */ +// CV_DIST_L1 =1, /* distance = |x1-x2| + |y1-y2| */ +// CV_DIST_L2 =2, /* the simple euclidean distance */ +// CV_DIST_C =3, /* distance = max(|x1-x2|,|y1-y2|) */ +// CV_DIST_L12 =4, /* L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */ +// CV_DIST_FAIR =5, /* distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */ +// CV_DIST_WELSCH =6, /* distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */ +// CV_DIST_HUBER =7 /* distance = |x| threshold ? max_value : 0 */ + CV_THRESH_BINARY_INV = C.CV_THRESH_BINARY_INV /* value = value > threshold ? 0 : max_value */ + CV_THRESH_TRUNC = C.CV_THRESH_TRUNC /* value = value > threshold ? threshold : value */ + CV_THRESH_TOZERO = C.CV_THRESH_TOZERO /* value = value > threshold ? value : 0 */ + CV_THRESH_TOZERO_INV = C.CV_THRESH_TOZERO_INV /* value = value > threshold ? 0 : value */ + CV_THRESH_MASK = C.CV_THRESH_MASK + CV_THRESH_OTSU = C.CV_THRESH_OTSU /* use Otsu algorithm to choose the optimal threshold value; + combine the flag with one of the above CV_THRESH_* values */ +) + +// /* Adaptive threshold methods */ +// enum +// { +// CV_ADAPTIVE_THRESH_MEAN_C =0, +// CV_ADAPTIVE_THRESH_GAUSSIAN_C =1 +// }; + +// /* FloodFill flags */ +// enum +// { +// CV_FLOODFILL_FIXED_RANGE =(1 << 16), +// CV_FLOODFILL_MASK_ONLY =(1 << 17) +// }; + +// /* Canny edge detector flags */ +// enum +// { +// CV_CANNY_L2_GRADIENT =(1 << 31) +// }; + +// /* Variants of a Hough transform */ +const ( + CV_HOUGH_STANDARD = C.CV_HOUGH_STANDARD + CV_HOUGH_PROBABILISTIC = C.CV_HOUGH_PROBABILISTIC + CV_HOUGH_MULTI_SCALE = C.CV_HOUGH_MULTI_SCALE + CV_HOUGH_GRADIENT = C.CV_HOUGH_GRADIENT +) + +// /* Fast search data structures */ +// struct CvFeatureTree; +// struct CvLSH; +// struct CvLSHOperations; + +// #ifdef __cplusplus +// } +// #endif + +// #endif diff --git a/opencv/opencv.c b/opencv/opencv.c index 220b592..36b956b 100644 --- a/opencv/opencv.c +++ b/opencv/opencv.c @@ -1,6 +1,7 @@ // Copyright 2011 . All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Updated by #include "opencv.h" #include "_cgo_export.h" @@ -14,8 +15,8 @@ // trackbar data struct TrackbarUserdata { - char* win_name; - char* bar_name; + schar* win_name; + schar* bar_name; int value; }; static struct TrackbarUserdata *trackbar_list[1000]; @@ -32,8 +33,8 @@ int GoOpenCV_CreateTrackbar( struct TrackbarUserdata *userdata = malloc(sizeof(*userdata)); trackbar_list[trackbar_list_len++] = userdata; - userdata->win_name = (char*)window_name; - userdata->bar_name = (char*)trackbar_name; + userdata->win_name = (schar*)window_name; + userdata->bar_name = (schar*)trackbar_name; userdata->value = value; return cvCreateTrackbar2(trackbar_name, window_name, @@ -58,7 +59,7 @@ void GoOpenCV_DestroyTrackbar(char* trackbar_name, char* window_name) { //----------------------------------------------------------------------------- static void mouseCallback(int event, int x, int y, int flags, void* param) { - char* name = (char*)param; + schar* name = (schar*)param; goMouseCallback(name, event, x, y, flags); } void GoOpenCV_SetMouseCallback(const char* window_name) { @@ -74,3 +75,11 @@ unsigned GoOpenCV_FOURCC_(int c1, int c2, int c3, int c4) { //----------------------------------------------------------------------------- +// A wrapper to the CvCmpFunc +CvCmpFunc GoOpenCV_CmpFunc(void* gofunc) +{ + int (*f)( const void*, const void*, void*) = gofunc; + return f; +} + +//----------------------------------------------------------------------------- diff --git a/opencv/opencv.h b/opencv/opencv.h index 0a909d0..cbc2435 100644 --- a/opencv/opencv.h +++ b/opencv/opencv.h @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. // // OpenCV Homepage: http://code.opencv.org +// Updated by #ifndef _GO_OPENCV_BINDING_H_ #define _GO_OPENCV_BINDING_H_ @@ -33,4 +34,13 @@ unsigned GoOpenCV_FOURCC_( int c1, int c2, int c3, int c4 ); +//----------------------------------------------------------------------------- + +typedef const void* CVoid; + +// A wrapper to the CvCmpFunc +CvCmpFunc GoOpenCV_CmpFunc(void* gofunc); + +//----------------------------------------------------------------------------- + #endif // _GO_OPENCV_BINDING_H_