├── samples ├── data │ └── images │ │ └── lena.jpg ├── filtering.go ├── format_conversion.go ├── contour-detect.go └── face-detect.go ├── statistic.go ├── histogram.go ├── neural.go ├── detection.go ├── resize.go ├── segmentation.go ├── README.md ├── texture.go ├── correlation.go ├── filter.go ├── background.go ├── conversion.go ├── operation.go └── LICENSE /samples/data/images/lena.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fwessels/go-cv/HEAD/samples/data/images/lena.jpg -------------------------------------------------------------------------------- /statistic.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | // TODO: Add statistics functions -------------------------------------------------------------------------------- /histogram.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | // TODO: Add histogram functionality -------------------------------------------------------------------------------- /neural.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | // TODO: Add neural network functionality -------------------------------------------------------------------------------- /detection.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | // TODO: Add Detection* functions 18 | -------------------------------------------------------------------------------- /resize.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | // StretchGray2x2 stretches input 8-bit gray image in two times. 22 | func StretchGray2x2(src, dst gocvsimd.View) { 23 | 24 | gocvsimd.SimdSse2StretchGray2x2(src, dst) 25 | } 26 | 27 | // TODO: Add ReduceGray2x2/3x3/4x4/5x5 28 | 29 | // TODO: Add ShiftBilinear -------------------------------------------------------------------------------- /samples/filtering.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "github.com/fwessels/go-cv" 20 | "github.com/fwessels/go-cv-simd/sse2" 21 | _ "image/jpeg" 22 | ) 23 | 24 | func main() { 25 | 26 | bgra, _ := gocvsimd.LoadImage("data/images/lena.jpg") 27 | 28 | fmt.Println(bgra) 29 | 30 | blurred := gocv.GaussianBlur3x3(bgra) 31 | 32 | fmt.Println(blurred) 33 | } -------------------------------------------------------------------------------- /samples/format_conversion.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "github.com/fwessels/go-cv" 20 | "github.com/fwessels/go-cv-simd/sse2" 21 | _ "image/jpeg" 22 | ) 23 | 24 | func main() { 25 | 26 | bgra, _ := gocvsimd.LoadImage("data/images/lena.jpg") 27 | 28 | fmt.Println(bgra) 29 | 30 | y, u, v := gocv.BgraToYuv444p(bgra) 31 | 32 | fmt.Println(y) 33 | fmt.Println(u) 34 | fmt.Println(v) 35 | } 36 | -------------------------------------------------------------------------------- /samples/contour-detect.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package main 16 | 17 | import ( 18 | _ "fmt" 19 | _ "github.com/fwessels/go-cv" 20 | _ "io/ioutil" 21 | ) 22 | 23 | func main() { 24 | 25 | // TODO: Port back from https://github.com/fwessels/go-cv-cgo/blob/master/samples/contour.go 26 | //buf, err := ioutil.ReadFile("./data/images/lena.jpg") 27 | //if err != nil { 28 | // panic("error loading from file") 29 | //} 30 | //mat := gocv.DecodeImageMemM(buf) 31 | // 32 | //contourDetector := gocv.ContourDetector{} 33 | // 34 | //contour := contourDetector.Init(mat) 35 | // 36 | //contours := contourDetector.Detect(contour, mat) 37 | // 38 | //fmt.Print(contours) 39 | // 40 | ////for contour := range contours { 41 | //// for c := range contour { 42 | //// fmt.Println(c) 43 | //// // Simd::DrawLine(image, contours[i][j - 1], contours[i][j], uint8_t(255)); 44 | //// } 45 | ////} 46 | // 47 | ////image.Save("result.pgm"); 48 | } 49 | -------------------------------------------------------------------------------- /samples/face-detect.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package main 16 | 17 | import ( 18 | _ "log" 19 | 20 | _ "github.com/fwessels/go-cv" 21 | _ "github.com/fwessels/go-cv-simd/sse2" 22 | ) 23 | 24 | func main() { 25 | 26 | // TODO: Port back from https://github.com/fwessels/go-cv-cgo/blob/master/samples/face-detect.go 27 | 28 | //objects := []gocv.Object{} 29 | // 30 | //img := gocv.View{} 31 | // 32 | //// Load image 33 | //if ok := img.Load("data/images/lena.pgm"); !ok { 34 | // log.Fatal("Cannot load image") 35 | //} 36 | // 37 | //// Initialize new detection engine 38 | //detect := gocv.NewDetection() 39 | // 40 | //// Load face detection xml 41 | //if ok := detect.Load("data/cascades/haar_face_0.xml"); !ok { 42 | // log.Fatal("face detection xml not loaded") 43 | //} 44 | // 45 | //// Init 46 | //if ok := detect.Init(img.Size()); !ok { 47 | // log.Fatal("cannot init detect with image size") 48 | //} 49 | // 50 | //// Detect 51 | //objects, ok := detect.Detect(img, objects) 52 | //if !ok { 53 | // log.Fatal("detection failed") 54 | //} 55 | // 56 | //if len(objects) == 0 { 57 | // log.Fatal("no objects found") 58 | //} 59 | // 60 | //// Print found face coordinates 61 | //log.Printf("%+v", objects[0].Rect) 62 | } 63 | -------------------------------------------------------------------------------- /segmentation.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | // SegmentationFillSingleHoles fills single holes in mask. 22 | // Mask must has 8-bit gray pixel format. 23 | func SegmentationFillSingleHoles(mask gocvsimd.View, index uint8) { 24 | 25 | gocvsimd.SimdSse2SegmentationFillSingleHoles(mask, uint64(index)) 26 | } 27 | 28 | // SegmentationChangeIndex changes certain index in mask. 29 | // Mask must has 8-bit gray pixel format. 30 | // For every point: 31 | // if(mask[i] == oldIndex) 32 | // mask[i] = newIndex; 33 | func SegmentationChangeIndex(mask gocvsimd.View, oldIndex, newIndex uint8) { 34 | 35 | gocvsimd.SimdSse2SegmentationChangeIndex(mask, uint64(oldIndex), uint64(newIndex)) 36 | } 37 | 38 | // SegmentationPropagate2x2 propagates mask index from parent (upper) to child (lower) level of mask pyramid with using 2x2 scan window. 39 | // For parent and child image the following must be true: parentWidth = (childWidth + 1)/2, parentHeight = (childHeight + 1)/2. 40 | // All images must have 8-bit gray pixel format. Size of different image is equal to the child image. 41 | func SegmentationPropagate2x2(parent, child, difference gocvsimd.View, currentIndex, invalidIndex, emptyIndex, differenceThreshold uint8) { 42 | 43 | gocvsimd.SimdSse2SegmentationPropagate2x2(parent, child, difference, uint64(currentIndex), uint64(invalidIndex), uint64(emptyIndex), uint64(differenceThreshold)) 44 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-cv 2 | 3 | go-cv is a computer vision and image processing library for Go using Golang assembly. It is a works-in-progress wrapper around the [Simd](https://github.com/ermig1979/Simd) library. For now most work has been done on the SSE2 version. 4 | 5 | ## SIMD 6 | The [Simd](https://github.com/ermig1979/Simd) Library is a highly optimized image processing library. It provides many useful high performance algorithms for image processing such as: 7 | - pixel format conversion 8 | - image scaling and filtration 9 | - extraction of statistic information from images 10 | - motion detection 11 | - object detection (HAAR and LBP classifier cascades) 12 | - classification 13 | - neural network 14 | 15 | The algorithms are optimized using different SIMD CPU extensions. In particular the library supports following CPU extensions: 16 | - x86/x64: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX and AVX2 17 | - ARM: NEON 18 | 19 | ## Installation 20 | 21 | ``` 22 | $ go get -u "github.com/fwessels/go-cv" 23 | ``` 24 | 25 | ## Samples 26 | 27 | See the `samples` directory for various sample algorithms. For example: 28 | 29 | ``` 30 | $ cd samples 31 | $ go run filtering.go 32 | ``` 33 | 34 | ## Performance compared to OpenCV 2.x 35 | 36 | A comparison against [go-opencv](https://github.com/lazywei/go-opencv) shows the following results: 37 | 38 | ``` 39 | OpenCV SSE2 40 | benchmark old ns/op new ns/op delta 41 | BenchmarkGaussian-8 74338 18481 -75.14% 42 | BenchmarkGaussianRGB-8 186024 57169 -69.27% 43 | BenchmarkBlur-8 110155 16623 -84.91% 44 | BenchmarkBlurRGB-8 293017 53716 -81.67% 45 | BenchmarkMedian3x3-8 129268 23270 -82.00% 46 | BenchmarkMedian3x3RGB-8 169857 65896 -61.21% 47 | BenchmarkMedian5x5-8 883311 131812 -85.08% 48 | BenchmarkMedian5x5RGB-8 1246845 388415 -68.85% 49 | ``` 50 | 51 | 52 | ## go-cv 53 | 54 | See the underlying package [go-cv](https://github.com/fwessels/go-cv/) for more information. 55 | 56 | ## License 57 | 58 | go-cv is released under the Apache License v2.0. You can find the complete text in the file LICENSE. 59 | -------------------------------------------------------------------------------- /texture.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | // TextureBoostedSaturatedGradient calculates boosted saturated gradients for given input image. 22 | // All images must have the same width, height and format (8-bit gray). 23 | // For border pixels: 24 | // dx[x, y] = 0; 25 | // dy[x, y] = 0; 26 | // For other pixels: 27 | // dx[x, y] = (saturation + max(-saturation, min(saturation, (src[x + 1, y] - src[x - 1, y]))))*boost; 28 | // dy[x, y] = (saturation + max(-saturation, min(saturation, (src[x, y + 1] - src[x, y - 1]))))*boost; 29 | func TextureBoostedSaturatedGradient(src gocvsimd.View, saturation, boost uint8, dx, dy gocvsimd.View) { 30 | 31 | gocvsimd.SimdSse2TextureBoostedSaturatedGradient(src, uint64(saturation), uint64(boost), dx, dy) 32 | } 33 | 34 | // TextureBoostedUv calculates boosted colorized texture feature of input image (actual for U and V components of YUV format). 35 | // All images must have the same width, height and format (8-bit gray). 36 | // For every pixel: 37 | // lo = 128 - (128/boost); 38 | // hi = 255 - lo; 39 | // dst[x, y] = max(lo, min(hi, src[i]))*boost; 40 | func TextureBoostedUv(src gocvsimd.View, boost uint8, dst gocvsimd.View) { 41 | 42 | gocvsimd.SimdSse2TextureBoostedUv(src, uint64(boost), dst) 43 | } 44 | 45 | // TextureGetDifferenceSum calculates difference between current image and background. 46 | // All images must have the same width, height and format (8-bit gray). 47 | // For every pixel: 48 | // sum += current - average(lo[i], hi[i]); 49 | func TextureGetDifferenceSum(src, lo, hi gocvsimd.View) int64 { 50 | 51 | return gocvsimd.SimdSse2TextureGetDifferenceSum(src, lo, hi) 52 | } 53 | 54 | // TexturePerformCompensation performs brightness compensation of input image. 55 | // All images must have the same width, height and format (8-bit gray). 56 | // For every pixel: 57 | // dst[i] = max(0, min(255, src[i] + shift)); 58 | func TexturePerformCompensation(src gocvsimd.View, shift int, dst gocvsimd.View) { 59 | 60 | gocvsimd.SimdSse2TexturePerformCompensation(src, shift, dst) 61 | } -------------------------------------------------------------------------------- /correlation.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | //AbsDifferenceSum gets sum of absolute difference of two gray 8-bit images. 22 | // Both images must have the same width and height. 23 | func AbsDifferenceSum(a, b gocvsimd.View) uint64 { 24 | 25 | return gocvsimd.SimdSse2AbsDifferenceSum(a, b) 26 | } 27 | // AbsDifferenceSumMasked gets sum of absolute difference of two gray 8-bit images based on gray 8-bit mask. 28 | // Gets the absolute difference sum for all points when mask[i] == index. 29 | // Both images and mask must have the same width and height. 30 | func AbsDifferenceSumMasked(a, b, mask gocvsimd.View, index uint8) uint64 { 31 | 32 | return gocvsimd.SimdSse2AbsDifferenceSumMasked(a, b, mask, uint64(index)) 33 | } 34 | // AbsDifferenceSums3x3 gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3. 35 | // Both images must have the same width and height. The image height and width must be equal or greater 3. 36 | // The sums are calculated with central part (indent width = 1) of the current image and with part of the background image with corresponding shift. 37 | // The shifts are lain in the range [-1, 1] for axis x and y. 38 | func AbsDifferenceSums3x3(current, background gocvsimd.View) [9]uint64 { 39 | 40 | return gocvsimd.SimdSse2AbsDifferenceSums3x3(current, background) 41 | } 42 | // AbsDifferenceSums3x3Masked gets 9 sums of absolute difference of two gray 8-bit images with various relative shifts in neighborhood 3x3 based on gray 8-bit mask. 43 | // Gets the absolute difference sums for all points when mask[i] == index. 44 | // Both images and mask must have the same width and height. The image height and width must be equal or greater 3. 45 | // The sums are calculated with central part (indent width = 1) of the current image and with part of the background image with the corresponding shift. 46 | // The shifts are lain in the range [-1, 1] for axis x and y. 47 | func AbsDifferenceSums3x3Masked(current, background, mask gocvsimd.View, index uint8) [9]uint64 { 48 | 49 | return gocvsimd.SimdSse2AbsDifferenceSums3x3Masked(current, background, mask, uint64(index)) 50 | } 51 | 52 | // AbsGradientSaturatedSum puts to destination 8-bit gray image saturated sum of absolute gradient for every point of source 8-bit gray image. 53 | // Both images must have the same width and height. 54 | // For border pixels: 55 | // dst[x, y] = 0; 56 | // For other pixels: 57 | // dx = abs(src[x + 1, y] - src[x - 1, y]); 58 | // dy = abs(src[x, y + 1] - src[x, y - 1]); 59 | // dst[x, y] = min(dx + dy, 255); 60 | func AbsGradientSaturatedSum(src, dst gocvsimd.View) { 61 | 62 | gocvsimd.SimdSse2AbsGradientSaturatedSum(src, dst) 63 | } 64 | // AddFeatureDifference adds feature difference to common difference in sum. 65 | // All images must have the same width, height and format (8-bit gray). 66 | // For every point: 67 | // excess = max(lo[i] - value[i], 0) + max(value[i] - hi[i], 0); 68 | // difference[i] += (weight * excess*excess) >> 16; 69 | // This function is used for difference estimation in algorithm of motion detection. 70 | func AddFeatureDifference(value, lo, hi gocvsimd.View, weight uint16, difference gocvsimd.View) { 71 | 72 | gocvsimd.SimdSse2AddFeatureDifference(value, lo, hi, uint64(weight), difference) 73 | } 74 | // SquaredDifferenceSum calculates sum of squared differences for two 8-bit gray images. 75 | // All images must have the same width and height. 76 | // For every point: 77 | // sum += (a[i] - b[i])*(a[i] - b[i]); 78 | func SquaredDifferenceSum(a, b gocvsimd.View) uint64 { 79 | 80 | return gocvsimd.SimdSse2SquaredDifferenceSum(a, b) 81 | } 82 | 83 | // SquaredDifferenceSumMasked calculates sum of squared differences for two images with using mask. 84 | // All images must have the same width, height and format (8-bit gray). 85 | // For every point: 86 | // if(mask[i] == index) 87 | // sum += (a[i] - b[i])*(a[i] - b[i]); 88 | func SquaredDifferenceSumMasked(a, b, mask gocvsimd.View, index uint8) uint64 { 89 | 90 | return gocvsimd.SimdSse2SquaredDifferenceSumMasked(a, b, mask, uint64(index)) 91 | } 92 | -------------------------------------------------------------------------------- /filter.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | func filter(src gocvsimd.View, f func(src, dst gocvsimd.View)) (dst gocvsimd.View) { 22 | 23 | dst = gocvsimd.View{} 24 | dst.Recreate(src.GetWidth(), src.GetHeight(), src.GetFormat()) 25 | 26 | gocvsimd.SimdSse2GaussianBlur3x3(src, dst) 27 | 28 | return dst 29 | } 30 | 31 | // GaussianBlur3x3 performs Gaussian blur filtration with window 3x3. 32 | // For every point: 33 | // dst[x, y] = (src[x-1, y-1] + 2*src[x, y-1] + src[x+1, y-1] + 34 | // 2*(src[x-1, y] + 2*src[x, y] + src[x+1, y]) + 35 | // src[x-1, y+1] + 2*src[x, y+1] + src[x+1, y+1] + 8) / 16; 36 | // All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA). 37 | func GaussianBlur3x3(src gocvsimd.View) (dst gocvsimd.View) { 38 | 39 | return filter(src, gocvsimd.SimdSse2GaussianBlur3x3) 40 | } 41 | // MeanFilter3x3 performs an averaging with window 3x3. 42 | // For every point: 43 | // dst[x, y] = (src[x-1, y-1] + src[x, y-1] + src[x+1, y-1] + 44 | // src[x-1, y] + src[x, y] + src[x+1, y] + 45 | // src[x-1, y+1] + src[x, y+1] + src[x+1, y+1] + 4) / 9; 46 | // All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA). 47 | func MeanFilter3x3(src gocvsimd.View) (dst gocvsimd.View) { 48 | 49 | return filter(src, gocvsimd.SimdSse2MeanFilter3x3) 50 | } 51 | // MedianFilterRhomb3x3 performs median filtration of input image (filter window is a rhomb 3x3). 52 | // All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA). 53 | func MedianFilterRhomb3x3(src gocvsimd.View) (dst gocvsimd.View) { 54 | 55 | return filter(src, gocvsimd.SimdSse2MedianFilterRhomb3x3) 56 | } 57 | // MedianFilterSquare3x3 performs median filtration of input image (filter window is a square 3x3). 58 | // All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA). 59 | func MedianFilterSquare3x3(src gocvsimd.View) (dst gocvsimd.View) { 60 | 61 | return filter(src, gocvsimd.SimdSse2MedianFilterSquare3x3) 62 | } 63 | // MedianFilterRhomb5x5 performs median filtration of input image (filter window is a rhomb 5x5). 64 | // All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA). 65 | func MedianFilterRhomb5x5(src gocvsimd.View) (dst gocvsimd.View) { 66 | 67 | return filter(src, gocvsimd.SimdSse2MedianFilterRhomb5x5) 68 | } 69 | // MedianFilterSquare5x5 performs median filtration of input image (filter window is a square 5x5). 70 | // All images must have the same width, height and format (8-bit gray, 16-bit UV, 24-bit BGR or 32-bit BGRA). 71 | func MedianFilterSquare5x5(src gocvsimd.View) (dst gocvsimd.View) { 72 | 73 | return filter(src, gocvsimd.SimdSse2MedianFilterSquare5x5) 74 | } 75 | // Laplace calculates Laplace's filter. 76 | // All images must have the same width and height. Input image must has 8-bit gray format, output image must has 16-bit integer format. 77 | func Laplace(src gocvsimd.View) (dst gocvsimd.View) { 78 | 79 | return filter(src, gocvsimd.SimdSse2Laplace) 80 | } 81 | 82 | // SobelDx calculates Sobel's filter along x axis. 83 | // All images must have the same width and height. Input image must has 8-bit gray format, output image must has 16-bit integer format. 84 | // For every point: 85 | // n dst[x, y] = (src[x+1,y-1] + 2*src[x+1, y] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x-1, y] + src[x-1, y+1]). 86 | func SobelDx(src gocvsimd.View) (dst gocvsimd.View) { 87 | 88 | return filter(src, gocvsimd.SimdSse2SobelDx) 89 | } 90 | 91 | // SobelDy calculates Sobel's filter along y axis. 92 | // All images must have the same width and height. Input image must has 8-bit gray format, output image must have a 16-bit integer format. 93 | // For every point: 94 | // dst[x, y] = (src[x-1,y+1] + 2*src[x, y+1] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x, y-1] + src[x+1, y-1]); 95 | func SobelDy(src gocvsimd.View) (dst gocvsimd.View) { 96 | 97 | return filter(src, gocvsimd.SimdSse2SobelDy) 98 | } 99 | 100 | // 101 | func ContourAnchors(src gocvsimd.View, step uint64, threshold int16, dst gocvsimd.View) { 102 | 103 | gocvsimd.SimdSse2ContourAnchors(src, step, uint64(threshold), dst) 104 | } 105 | -------------------------------------------------------------------------------- /background.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | // BackgroundGrowRangeSlow performs background update (initial grow, slow mode). 22 | // All images must have the same width, height and format (8-bit gray). 23 | // For every point: 24 | // lo[i] -= value[i] < lo[i] ? 1 : 0; 25 | // hi[i] += value[i] > hi[i] ? 1 : 0; 26 | // This function is used for background updating in motion detection algorithm. 27 | func BackgroundGrowRangeSlow(value, lo, hi gocvsimd.View) { 28 | 29 | gocvsimd.SimdSse2BackgroundGrowRangeSlow(value, lo, hi) 30 | } 31 | 32 | // BackgroundGrowRangeFast performs background update (initial grow, fast mode). 33 | // All images must have the same width, height and format (8-bit gray). 34 | // For every point: 35 | // lo[i] = value[i] < lo[i] ? value[i] : lo[i]; 36 | // hi[i] = value[i] > hi[i] ? value[i] : hi[i]; 37 | // This function is used for background updating in motion detection algorithm. 38 | func BackgroundGrowRangeFast(value, lo, hi gocvsimd.View) { 39 | 40 | gocvsimd.SimdSse2BackgroundGrowRangeFast(value, lo, hi) 41 | } 42 | 43 | // BackgroundIncrementCount performs collection of background statistic. 44 | // All images must have the same width, height and format (8-bit gray). 45 | // Updates background statistic counters for every point: 46 | // loCount[i] += (value[i] < loValue[i] && loCount[i] < 255) ? 1 : 0; 47 | // hiCount[i] += (value[i] > hiValue[i] && hiCount[i] < 255) ? 1 : 0; 48 | // This function is used for background updating in motion detection algorithm. 49 | func BackgroundIncrementCount(value, lo, hi, loCount, hiCount gocvsimd.View) { 50 | 51 | gocvsimd.SimdSse2BackgroundIncrementCount(value, lo, hi, loCount, hiCount) 52 | } 53 | 54 | // BackgroundAdjustRange performs adjustment of background range. 55 | // All images must have the same width, height and format (8-bit gray). 56 | // Adjusts background range for every point: 57 | // loValue[i] -= (loCount[i] > threshold && loValue[i] > 0) ? 1 : 0; 58 | // loValue[i] += (loCount[i] < threshold && loValue[i] < 255) ? 1 : 0; 59 | // loCount[i] = 0; 60 | // hiValue[i] += (hiCount[i] > threshold && hiValue[i] < 255) ? 1 : 0; 61 | // hiValue[i] -= (hiCount[i] < threshold && hiValue[i] > 0) ? 1 : 0; 62 | // hiCount[i] = 0; 63 | // This function is used for background updating in motion detection algorithm. 64 | func BackgroundAdjustRange(loCount, loValue, hiCount, hiValue gocvsimd.View, threshold uint8) { 65 | 66 | gocvsimd.SimdSse2BackgroundAdjustRange(loCount, loValue, hiCount, hiValue, uint64(threshold)) 67 | } 68 | 69 | // BackgroundAdjustRangeMasked performs adjustment of background range with using adjust range mask. 70 | // All images must have the same width, height and format (8-bit gray). 71 | // Adjusts background range for every point: 72 | // if(mask[i]) 73 | // { 74 | // loValue[i] -= (loCount[i] > threshold && loValue[i] > 0) ? 1 : 0; 75 | // loValue[i] += (loCount[i] < threshold && loValue[i] < 255) ? 1 : 0; 76 | // loCount[i] = 0; 77 | // hiValue[i] += (hiCount[i] > threshold && hiValue[i] < 255) ? 1 : 0; 78 | // hiValue[i] -= (hiCount[i] < threshold && hiValue[i] > 0) ? 1 : 0; 79 | // hiCount[i] = 0; 80 | // } 81 | // This function is used for background updating in motion detection algorithm. 82 | func BackgroundAdjustRangeMasked(loCount, loValue, hiCount, hiValue gocvsimd.View, threshold uint8, mask gocvsimd.View) { 83 | 84 | gocvsimd.SimdSse2BackgroundAdjustRangeMasked(loCount, loValue, hiCount, hiValue, uint64(threshold), mask) 85 | } 86 | 87 | // BackgroundShiftRange shifts background range. 88 | //All images must have the same width, height and format (8-bit gray). 89 | // For every point: 90 | // if (value[i] > hi[i]) 91 | // { 92 | // lo[i] = min(lo[i] + value[i] - hi[i], 255); 93 | // hi[i] = value[i]; 94 | // } 95 | // if (lo[i] > value[i]) 96 | // { 97 | // lo[i] = value[i]; 98 | // hi[i] = max(hi[i] - lo[i] + value[i], 0); 99 | // } 100 | // This function is used for fast background updating in motion detection algorithm. 101 | func BackgroundShiftRange(value, lo, hi gocvsimd.View) { 102 | 103 | gocvsimd.SimdSse2BackgroundShiftRange(value, lo, hi) 104 | } 105 | 106 | // BackgroundShiftRangeMasked shifts background range with using shift range mask. 107 | // All images must have the same width, height and format (8-bit gray). 108 | // For every point: 109 | // if(mask[i]) 110 | // { 111 | // if (value[i] > hi[i]) 112 | // { 113 | // lo[i] = min(lo[i] + value[i] - hi[i], 255); 114 | // hi[i] = value[i]; 115 | // } 116 | // if (lo[i] > value[i]) 117 | // { 118 | // lo[i] = value[i]; 119 | // hi[i] = max(hi[i] - lo[i] + value[i], 0); 120 | // } 121 | // } 122 | // This function is used for fast background updating in motion detection algorithm. 123 | func BackgroundShiftRangeMasked(value, lo, hi, mask gocvsimd.View) { 124 | 125 | gocvsimd.SimdSse2BackgroundShiftRangeMasked(value, lo, hi, mask) 126 | } 127 | -------------------------------------------------------------------------------- /conversion.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | // AlphaBlending performs alpha blending operation. 22 | // All images must have the same width and height. Source and destination images must have the same format (8 bit per channel, for example GRAY8, BGR24 or BGRA32). Alpha must be 8-bit gray image. 23 | // For every point: 24 | // dst[i] = (src[i]*alpha[i] + dst[i]*(255 - alpha[i]))/255; 25 | //This function is used for image drawing. 26 | func AlphaBlending(src, alpha, dst gocvsimd.View) { 27 | 28 | gocvsimd.SimdSse2AlphaBlending(src, alpha, dst) 29 | } 30 | //BgraToGray converts 32-bit BGRA image to 8-bit gray image. 31 | // All images must have the same width and height. 32 | func BgraToGray(bgra gocvsimd.View) (gray gocvsimd.View) { 33 | 34 | gray = gocvsimd.View{} 35 | gray.Recreate(bgra.GetWidth(), bgra.GetHeight(), gocvsimd.GRAY8) 36 | 37 | gocvsimd.SimdSse2BgraToGray(bgra, gray) 38 | 39 | return gray 40 | } 41 | 42 | func bgratoyuv(bgra gocvsimd.View, f func(bgra, y, u, v gocvsimd.View)) (y, u, v gocvsimd.View) { 43 | 44 | y, u, v = gocvsimd.View{}, gocvsimd.View{}, gocvsimd.View{} 45 | y.Recreate(bgra.GetWidth(), bgra.GetHeight(), gocvsimd.GRAY8) 46 | u.Recreate(bgra.GetWidth(), bgra.GetHeight(), gocvsimd.GRAY8) 47 | v.Recreate(bgra.GetWidth(), bgra.GetHeight(), gocvsimd.GRAY8) 48 | 49 | gocvsimd.SimdSse2BgraToYuv420p(bgra, y, u, v) 50 | 51 | return y, u, v 52 | } 53 | 54 | // BgraToYuv420p converts 32-bit BGRA image to YUV420P. 55 | // The input BGRA and output Y images must have the same width and height. 56 | // The input U and V images must have the same width and height (half size relative to Y component). 57 | func BgraToYuv420p(bgra gocvsimd.View) (y, u, v gocvsimd.View) { 58 | 59 | return bgratoyuv(bgra, gocvsimd.SimdSse2BgraToYuv420p) 60 | } 61 | 62 | // BgraToYuv422p converts 32-bit BGRA image to YUV422P. 63 | // The input BGRA and output Y images must have the same width and height. 64 | // The input U and V images must have the same width and height (their width is equal to half width of Y component). 65 | func BgraToYuv422p(bgra gocvsimd.View) (y, u, v gocvsimd.View) { 66 | 67 | return bgratoyuv(bgra, gocvsimd.SimdSse2BgraToYuv422p) 68 | } 69 | 70 | // BgraToYuv444p converts 32-bit BGRA image to YUV444P. 71 | // The input BGRA and output Y, U and V images must have the same width and height. 72 | func BgraToYuv444p(bgra gocvsimd.View) (y, u, v gocvsimd.View) { 73 | 74 | return bgratoyuv(bgra, gocvsimd.SimdSse2BgraToYuv444p) 75 | } 76 | // GrayToBgra converts 8-bit gray image to 32-bit BGRA image. 77 | // All images must have the same width and height. 78 | func GrayToBgra(gray gocvsimd.View) (bgra gocvsimd.View) { 79 | 80 | bgra = gocvsimd.View{} 81 | bgra.Recreate(gray.GetWidth(), gray.GetHeight(), gocvsimd.BGRA32) 82 | 83 | gocvsimd.SimdSse2GrayToBgra(gray, bgra) 84 | 85 | return bgra 86 | } 87 | 88 | // DeinterleaveUv deinterleaves 16-bit UV interleaved image into separated 8-bit U and V planar images. 89 | // All images must have the same width and height. 90 | // This function used for NV12 to YUV420P conversion. 91 | func DeinterleaveUv(uv gocvsimd.View) (u, v gocvsimd.View) { 92 | 93 | u, v = gocvsimd.View{}, gocvsimd.View{} 94 | u.Recreate(uv.GetWidth(), uv.GetHeight(), gocvsimd.GRAY8) 95 | v.Recreate(uv.GetWidth(), uv.GetHeight(), gocvsimd.GRAY8) 96 | 97 | gocvsimd.SimdSse2DeinterleaveUv(uv, u, v) 98 | 99 | return u, v 100 | } 101 | // FillBgr fills pixels data of 24-bit BGR image by given color(blue, green, red). 102 | func FillBgr(dst gocvsimd.View, blue, green, red int) { 103 | 104 | gocvsimd.SimdSse2FillBgr(dst, blue, green, red) 105 | } 106 | 107 | // FillBgra fills pixels data of 32-bit BGRA image by given color(blue, green, red, alpha). 108 | func FillBgra(dst gocvsimd.View, blue, green, red, alpha int) { 109 | 110 | gocvsimd.SimdSse2FillBgra(dst, blue, green, red, alpha) 111 | } 112 | 113 | // Int16ToGray converts 16-bit signed integer image to 8-bit gray image with saturation. 114 | // All images must have the same width and height. 115 | func Int16ToGray(src gocvsimd.View) (dst gocvsimd.View) { 116 | 117 | dst = gocvsimd.View{} 118 | dst.Recreate(dst.GetWidth(), dst.GetHeight(), gocvsimd.GRAY8) 119 | 120 | gocvsimd.SimdSse2Int16ToGray(src, dst) 121 | 122 | return dst 123 | } 124 | 125 | func yuvtobgra(y, u, v gocvsimd.View, alpha uint8, f func(y, u, v, bgra gocvsimd.View, alpha uint64)) (bgra gocvsimd.View) { 126 | 127 | bgra = gocvsimd.View{} 128 | bgra.Recreate(y.GetWidth(), y.GetHeight(), gocvsimd.BGRA32) 129 | 130 | f(y, u, v, bgra, uint64(alpha)) 131 | 132 | return bgra 133 | } 134 | 135 | //Yuv420pToBgra converts YUV420P image to 32-bit BGRA image. 136 | // The input Y and output BGRA images must have the same width and height. 137 | // The input U and V images must have the same width and height (half size relative to Y component). 138 | func Yuv420pToBgra(y, u, v gocvsimd.View, alpha uint8) (bgra gocvsimd.View) { 139 | 140 | return yuvtobgra(y, u, v, alpha, gocvsimd.SimdSse2Yuv420pToBgra) 141 | } 142 | 143 | // Yuv422pToBgra converts YUV422P image to 32-bit BGRA image. 144 | // The input Y and output BGRA images must have the same width and height. 145 | // The input U and V images must have the same width and height (their width is equal to half width of Y component). 146 | func Yuv422pToBgra(y, u, v gocvsimd.View, alpha uint8) (bgra gocvsimd.View) { 147 | 148 | return yuvtobgra(y, u, v, alpha, gocvsimd.SimdSse2Yuv422pToBgra) 149 | } 150 | // Yuv444pToBgra converts YUV444P image to 32-bit BGRA image. 151 | // The input Y, U, V and output BGRA images must have the same width and height. 152 | func Yuv444pToBgra(y, u, v gocvsimd.View, alpha uint8) (bgra gocvsimd.View) { 153 | 154 | return yuvtobgra(y, u, v, alpha, gocvsimd.SimdSse2Yuv444pToBgra) 155 | } 156 | 157 | // TODO: Add Reorder16bit/32bit/64bit -------------------------------------------------------------------------------- /operation.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | package gocv 16 | 17 | import ( 18 | "github.com/fwessels/go-cv-simd/sse2" 19 | ) 20 | 21 | // Binarization performs binarization of 8-bit gray image. 22 | // All images must have 8-bit gray format and must have the same width and height. 23 | // For every point: 24 | // dst[i] = compare(src[i], value) ? positive : negative; 25 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 26 | func Binarization(src gocvsimd.View, value, positive, negative uint8, dst gocvsimd.View, compareType uint8) { 27 | 28 | gocvsimd.SimdSse2Binarization(src, uint64(value), uint64(positive), uint64(negative), dst, uint64(compareType)) 29 | } 30 | 31 | // AveragingBinarization performs averaging binarization of 8-bit gray image. 32 | // All images must have 8-bit gray format and must have the same width and height. 33 | // For every point: 34 | // sum = 0; area = 0; 35 | // for(dy = -neighborhood; dy <= neighborhood; ++dy) 36 | // { 37 | // for(dx = -neighborhood; dx <= neighborhood; ++dx) 38 | // { 39 | // if(x + dx >= 0 && x + dx < width && y + dy >= 0 && y + dy < height) 40 | // { 41 | // area++; 42 | // if(compare(src[x + dx, x + dy], value)) 43 | // sum++; 44 | // } 45 | // } 46 | // } 47 | // dst[x, y] = sum*255 > area*threshold ? positive : negative; 48 | //where compare(a, b) depends from compareType (see ::SimdCompareType). 49 | func AveragingBinarization(src gocvsimd.View, value uint8, neighborhood uint64, threshold, positive, negative uint8, dst gocvsimd.View, compareType uint8) { 50 | 51 | gocvsimd.SimdSse2AveragingBinarization(src, uint64(value), neighborhood, uint64(threshold), uint64(positive), uint64(negative), dst, uint64(compareType)) 52 | } 53 | 54 | // ConditionalCount8u calculates number of points satisfying certain condition for 8-bit gray image. 55 | // For every point: 56 | // if(compare(src[i], value)) 57 | // count++; 58 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 59 | func ConditionalCount8u(src gocvsimd.View, value uint8, compareType uint8) uint32 { 60 | 61 | return gocvsimd.SimdSse2ConditionalCount8u(src, uint64(value), uint64(compareType)) 62 | } 63 | 64 | // ConditionalCount16i calculates the number of points satisfying certain condition for 16-bit signed integer image. 65 | // For every point: 66 | // if(compare(src[i], value)) 67 | // count++; 68 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 69 | func ConditionalCount16i(src gocvsimd.View, value int16, compareType uint8) uint32 { 70 | 71 | return gocvsimd.SimdSse2ConditionalCount16i(src, uint64(value), uint64(compareType)) 72 | } 73 | 74 | // ConditionalSum calculates sum of image points when mask points satisfying certain condition. 75 | // All images must have 8-bit gray format and must have the same width and height. 76 | // For every point: 77 | // if(compare(mask[i], value)) 78 | // sum += src[i]; 79 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 80 | func ConditionalSum(src, mask gocvsimd.View, value, compareType uint8) uint64 { 81 | 82 | return gocvsimd.SimdSse2ConditionalSum(src, mask, uint64(value), uint64(compareType)) 83 | 84 | } 85 | 86 | // ConditionalSquareSum calculates sum of squared image points when mask points satisfying certain condition. 87 | // All images must have 8-bit gray format and must have the same width and height. 88 | // For every point: 89 | // if(compare(mask[i], value)) 90 | // sum += src[i]*src[i]; 91 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 92 | func ConditionalSquareSum(src, mask gocvsimd.View, value, compareType uint8) uint64 { 93 | 94 | return gocvsimd.SimdSse2ConditionalSquareSum(src, mask, uint64(value), uint64(compareType)) 95 | } 96 | 97 | // ConditionalSquareGradientSum calculates sum of squared gradient of image points when mask points satisfying certain condition. 98 | // All images must have 8-bit gray format and must have the same width and height. The image height and width must be equal or greater 3. 99 | // For every point except border: 100 | // if(compare(mask[x, y], value)) 101 | // { 102 | // dx = src[x + 1, y] - src[x - 1, y]; 103 | // dy = src[x, y + 1] - src[x, y - 1]; 104 | // sum += dx*dx + dy*dy; 105 | // } 106 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 107 | func ConditionalSquareGradientSum(src, mask gocvsimd.View, value, compareType uint8) uint64 { 108 | 109 | return gocvsimd.SimdSse2ConditionalSquareGradientSum(src, mask, uint64(value), uint64(compareType)) 110 | } 111 | 112 | // ConditionalFill fills pixels of 8-bit gray image by given value if corresponding pixels of input 8-bit gray image satisfy certain condition. 113 | // All images must have the same width and height. 114 | // For every point: 115 | // if(compare(src[i], threshold)) 116 | // dst[i] = value; 117 | // where compare(a, b) depends from compareType (see ::SimdCompareType). 118 | func ConditionalFill(src gocvsimd.View, threshold, compareType, value uint8, dst gocvsimd.View) { 119 | 120 | gocvsimd.SimdSse2ConditionalFill(src, uint64(threshold), uint64(compareType), uint64(value), dst) 121 | } 122 | 123 | // OperationBinary8u performs given operation between two images. 124 | // All images must have the same width, height and format (8-bit gray, 16-bit UV (UV plane of NV12 pixel format), 24-bit BGR or 32-bit BGRA). 125 | func OperationBinary8u(a, b, dst gocvsimd.View, _type uint8) { 126 | 127 | gocvsimd.SimdSse2OperationBinary8u(a, b, dst, uint64(_type)) 128 | } 129 | 130 | // OperationBinary16i performs given operation between two images. 131 | // All images must have the same width, height and ::SimdPixelFormatInt16 pixel format. 132 | func OperationBinary16i(a, b, dst gocvsimd.View, _type uint8) { 133 | 134 | gocvsimd.SimdSse2OperationBinary16i(a, b , dst, uint64(_type)) 135 | } 136 | 137 | // VectorProduct calculates result 8-bit gray image as product of two vectors. 138 | // For all points: 139 | // dst[x, y] = horizontal[x]*vertical[y]/255; 140 | func VectorProduct(vertical, horizontal, dst gocvsimd.View) { 141 | 142 | gocvsimd.SimdSse2VectorProduct(vertical, horizontal, dst) 143 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------