All Projects → vvmnnnkv → SwiftCV

vvmnnnkv / SwiftCV

Licence: other
Minimal Swift for TensorFlow OpenCV bindings

Programming Languages

Jupyter Notebook
11667 projects
C++
36643 projects - #6 most used programming language
swift
15916 projects

Projects that are alternatives of or similar to SwiftCV

Deferred
Work with values that haven't been determined yet.
Stars: ✭ 406 (+997.3%)
Mutual labels:  swiftpm
Rock
With Rock you can easily install CLIs built with Swift Package Manager. Prefer vknabel/Archery and yonaskolb/Mint instead
Stars: ✭ 13 (-64.86%)
Mutual labels:  swiftpm
Materialactivityindicator
Material Activity Indicator
Stars: ✭ 109 (+194.59%)
Mutual labels:  swiftpm
Hero
Elegant transition library for iOS & tvOS
Stars: ✭ 20,547 (+55432.43%)
Mutual labels:  swiftpm
Imagescout
A Swift implementation of fastimage. Supports PNG, GIF, and JPEG.
Stars: ✭ 940 (+2440.54%)
Mutual labels:  swiftpm
Scenekit Scnline
Draw a tube or thick line in SceneKit
Stars: ✭ 49 (+32.43%)
Mutual labels:  swiftpm
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+9927.03%)
Mutual labels:  swiftpm
Swift Docker
Build & test your swift packages using docker - `swift docker test`
Stars: ✭ 179 (+383.78%)
Mutual labels:  swiftpm
Sdwebimageswiftui
SwiftUI Image loading and Animation framework powered by SDWebImage
Stars: ✭ 844 (+2181.08%)
Mutual labels:  swiftpm
Swiftcrossplatformframework
Tutorial to create cross platform framework for Swift compatible with Carthage and SwiftPM
Stars: ✭ 98 (+164.86%)
Mutual labels:  swiftpm
Reflection
DEPRECATED
Stars: ✭ 592 (+1500%)
Mutual labels:  swiftpm
Swift Benchmark
A swift library to benchmark code snippets.
Stars: ✭ 659 (+1681.08%)
Mutual labels:  swiftpm
Dikit
Dependency Injection Framework for Swift, inspired by KOIN.
Stars: ✭ 77 (+108.11%)
Mutual labels:  swiftpm
Fiber2d
Cross-platform 2D Game Engine in pure Swift
Stars: ✭ 415 (+1021.62%)
Mutual labels:  swiftpm
Venice
Coroutines, structured concurrency and CSP for Swift on macOS and Linux.
Stars: ✭ 1,501 (+3956.76%)
Mutual labels:  swiftpm
Keyboardobserving
⌨️A Combine-based way to observe and adjust for Keyboard notifications in SwiftUI
Stars: ✭ 399 (+978.38%)
Mutual labels:  swiftpm
Scenekit Bezier Animations
Create animations over Bezier curves of any number of points
Stars: ✭ 35 (-5.41%)
Mutual labels:  swiftpm
Swipycell
Easy to use UITableViewCell implementing swiping to trigger actions.
Stars: ✭ 230 (+521.62%)
Mutual labels:  swiftpm
Zewo
Lightweight library for web server applications in Swift on macOS and Linux powered by coroutines.
Stars: ✭ 1,856 (+4916.22%)
Mutual labels:  swiftpm
Packageconfig
A Swift Package that allows you to define configuration settings inside a Package.swift
Stars: ✭ 88 (+137.84%)
Mutual labels:  swiftpm

SwiftCV

Minimal Swift for TensorFlow OpenCV4 bindings, partially ported from gocv.

OpenCV Functions exposed:

  • resize
  • getRotationMatrix2D
  • warpAffine
  • copyMakeBorder
  • GaussianBlur
  • remap
  • imdecode
  • imread
  • cvtColor
  • flip
  • transpose
  • VideoCapture (Not supported on Colab)
  • ImShow (Not supported on Colab)
  • WaitKey

OpenCV's Mat can be converted to S4TF's Tensor and ShapedArray types (and back).

See Extra/Tests.ipynb and Tests as an example of usage.

Try demo notebook in Colab.

Usage

Installation

Include as SwiftPM package:

.package(url: "https://github.com/vvmnnnkv/SwiftCV.git", .branch("master"))

In a Jupyter Notebook:

%system curl -sL https://github.com/vvmnnnkv/opencv-colab/raw/master/opencv4.tar.gz | tar zxf - -C / && ldconfig /opt/opencv-4.1.0/lib/ && ln -s /opt/opencv-4.1.0/lib/pkgconfig/opencv4.pc /usr/lib/pkgconfig/opencv4.pc

%install-location $cwd/swift-packages
%install '.package(url: "https://github.com/vvmnnnkv/SwiftCV.git", .branch("master"))' SwiftCV

NOTE: OpenCV4 must installed in order for package to compile.

Run the install/install_cv4.sh script (written by Jeremy Howard) to install opencv4.

API

Loading an image

// load image in memory
let url = "https://live.staticflickr.com/2842/11335865374_0b202e2dc6_o_d.jpg"
let imgContent = Data(contentsOf: URL(string: url)!)

// make opencv image
var cvImg = imdecode(imgContent)
// convert color scheme to RGB
cvImg = cvtColor(cvImg, nil, ColorConversionCode.COLOR_BGR2RGB)
show_img(cvImg)

Rotate

resize(cvImg, nil, Size(100, 50), 0, 0, InterpolationFlag.INTER_AREA)

Zoom / Crop

let zoomMat = getRotationMatrix2D(Size(cvImg.cols, cvImg.rows / 2), 0, 2)
warpAffine(cvImg, nil, zoomMat, Size(600, 600))

Rotate

let rotMat = getRotationMatrix2D(Size(cvImg.cols / 2, cvImg.rows / 2), 20, 1)
warpAffine(cvImg, nil, rotMat, Size(cvImg.cols, cvImg.rows))

Pad

copyMakeBorder(cvImg, nil, 40, 40, 40, 40, BorderType.BORDER_CONSTANT, RGBA(0, 127, 0, 0))

Blur

GaussianBlur(cvImg, nil, Size(25, 25))

Flip

flip(cvImg, nil, FlipMode.HORIZONTAL)

Transpose

transpose(cvImg, nil)

Viewing webcam

let cap = VideoCapture(0)
// Optional, reduces latency a bit
cap.set(VideoCaptureProperties.CAP_PROP_BUFFERSIZE, 1)

let frame = Mat()

while true {
    cap.read(into: frame)
    ImShow(image: frame)
    WaitKey(delay: 1)
}

Lightning / Contrast

This requires Swift for TensorFlow.

// convert image to floats Tensor
var imgTens = Tensor<Float>(Tensor<UInt8>(cvMat: cvImg)!) / 255
let contr:Float = 1.8
let lightn:Float = 0.2
let mean = imgTens.mean()
imgTens = (imgTens - mean) * contr + mean + lightn

Noise

This requires Swift for TensorFlow.

// convert image to Tensor
var imgTens = Tensor<Float>(Tensor<UInt8>(cvMat: cvImg)!) / 255
let randTens = Tensor<Float>(randomNormal: imgTens.shape) * 0.1
imgTens += randTens

Disclaimer

Currently this package is just an example of OpenCV/S4TF integration with no safety checks and guarantees to work properly :)

License

OpenCV C API, (c) Copyright gocv authors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].