Skip to content

Commit

Permalink
Add support for native VFW implementation on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2brain committed Oct 29, 2018
1 parent 72f1293 commit d587011
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 51 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@ or

### Requirements

* [OpenCV](http://opencv.org/)
* [libjpeg-turbo](https://www.libjpeg-turbo.org/)
* [libjpeg-turbo](https://www.libjpeg-turbo.org/) (use `-tags jpeg` to build without `CGo`)

On Linux/RPi native Go [V4L](https://github.com/korandiz/v4l) implementation is used to capture images.
On Windows [Video for Windows (VfW)](https://en.wikipedia.org/wiki/Video_for_Windows) framework is used over win32 API.

### Installation

go get -u github.com/gen2brain/cam2ip

### Build tags

* `cv3` - build with `OpenCV` 3.x [gocv](https://github.com/hybridgroup/gocv), default is version 2.x via [go-opencv](https://github.com/lazywei/go-opencv)
* `native` - build with native Go [V4L](https://github.com/korandiz/v4l) implementation on Linux/RPi instead of `OpenCV`
* `cv2` - build with `OpenCV` 2.x ([go-opencv](https://github.com/lazywei/go-opencv))
* `cv3` - build with `OpenCV` 3.x ([gocv](https://github.com/hybridgroup/gocv))
* `jpeg` - build with native Go `image/jpeg` instead of `libjpeg-turbo`

### Download

Binaries are compiled with static OpenCV/libjpeg-turbo libraries, they should just work:

- [Linux 64bit](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-64bit.tar.gz)
- [Linux 64bit native](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-64bit-native.tar.gz)
- [Linux 64bit OpenCV](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-64bit-cv2.tar.gz)
- [RPi 32bit](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi.tar.gz)
- [RPi 32bit native](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi-native.tar.gz)
- [RPi 32bit OpenCV](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi-cv2.tar.gz)
- [RPi 32bit Static](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi-nocgo.tar.gz)
- [RPi3 32bit](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi3.tar.gz)
- [RPi3 32bit native](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi3-native.tar.gz)
- [Windows 32bit](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5.zip)
- [RPi3 32bit OpenCV](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-RPi3-cv2.tar.gz)
- [Windows 32bit](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-32bit.zip)
- [Windows 32bit OpenCV](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-32bit-cv2.zip)
- [Windows 64bit](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-64bit.zip)
- [Windows 64bit OpenCV](https://github.com/gen2brain/cam2ip/releases/download/1.5/cam2ip-1.5-64bit-cv2.zip)


### Installation
Expand Down
28 changes: 7 additions & 21 deletions cam2ip.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !native

package main

import (
Expand All @@ -9,12 +7,11 @@ import (

"github.com/gen2brain/cam2ip/camera"
"github.com/gen2brain/cam2ip/server"
"github.com/gen2brain/cam2ip/video"
)

const (
name = "cam2ip"
version = "1.4"
version = "1.5"
)

func main() {
Expand All @@ -28,7 +25,6 @@ func main() {
flag.BoolVar(&srv.NoWebGL, "nowebgl", false, "Disable WebGL drawing of images (html handler)")
flag.StringVar(&srv.Bind, "bind-addr", ":56000", "Bind address")
flag.StringVar(&srv.Htpasswd, "htpasswd-file", "", "Path to htpasswd file, if empty auth is disabled")
flag.StringVar(&srv.FileName, "video-file", "", "Use video file instead of camera")
flag.Parse()

srv.Name = name
Expand All @@ -50,24 +46,14 @@ func main() {
}
}

if srv.FileName != "" {
vid, err := video.New(video.Options{srv.FileName, srv.Rotate})
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}

srv.Reader = vid
} else {
cam, err := camera.New(camera.Options{srv.Index, srv.Rotate, srv.FrameWidth, srv.FrameHeight})
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}

srv.Reader = cam
cam, err := camera.New(camera.Options{srv.Index, srv.Rotate, srv.FrameWidth, srv.FrameHeight})
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}

srv.Reader = cam

defer srv.Reader.Close()

fmt.Fprintf(os.Stderr, "Listening on %s\n", srv.Bind)
Expand Down
28 changes: 20 additions & 8 deletions cam2ip_native.go → cam2ip_cv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build native
// +build cv2,cv3

package main

Expand All @@ -9,11 +9,12 @@ import (

"github.com/gen2brain/cam2ip/camera"
"github.com/gen2brain/cam2ip/server"
"github.com/gen2brain/cam2ip/video"
)

const (
name = "cam2ip"
version = "1.4"
version = "1.5"
)

func main() {
Expand All @@ -27,6 +28,7 @@ func main() {
flag.BoolVar(&srv.NoWebGL, "nowebgl", false, "Disable WebGL drawing of images (html handler)")
flag.StringVar(&srv.Bind, "bind-addr", ":56000", "Bind address")
flag.StringVar(&srv.Htpasswd, "htpasswd-file", "", "Path to htpasswd file, if empty auth is disabled")
flag.StringVar(&srv.FileName, "video-file", "", "Use video file instead of camera")
flag.Parse()

srv.Name = name
Expand All @@ -48,13 +50,23 @@ func main() {
}
}

cam, err := camera.New(camera.Options{srv.Index, srv.Rotate, srv.FrameWidth, srv.FrameHeight})
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}
if srv.FileName != "" {
vid, err := video.New(video.Options{srv.FileName, srv.Rotate})
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}

srv.Reader = vid
} else {
cam, err := camera.New(camera.Options{srv.Index, srv.Rotate, srv.FrameWidth, srv.FrameHeight})
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}

srv.Reader = cam
srv.Reader = cam
}

defer srv.Reader.Close()

Expand Down
2 changes: 1 addition & 1 deletion camera/camera_const.go → camera/camera_const_cv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !native
// +build cv2 cv3

package camera

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build native
// +build !cv2,!cv3

package camera

Expand Down
2 changes: 1 addition & 1 deletion camera/camera.go → camera/camera_cv2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !cv3,!native
// +build cv2,!cv3

// Package camera.
package camera
Expand Down
2 changes: 1 addition & 1 deletion camera/camera_cv3.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build cv3,!native
// +build cv3,!cv2

// Package camera.
package camera
Expand Down
2 changes: 1 addition & 1 deletion camera/camera_native_linux.go → camera/camera_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build native
// +build !cv2,!cv3

// Package camera.
package camera
Expand Down
Loading

0 comments on commit d587011

Please sign in to comment.