mirror of
https://github.com/gen2brain/cam2ip.git
synced 2025-12-16 04:18:39 +00:00
Drop support for cv2, rename tag
This commit is contained in:
@@ -21,8 +21,7 @@ You can also use apps like `ffplay` or `vlc`:
|
|||||||
|
|
||||||
### Build tags
|
### Build tags
|
||||||
|
|
||||||
* `cv2` - build with `OpenCV` 2.x ([go-opencv](https://github.com/lazywei/go-opencv))
|
* `opencv` - use `OpenCV` to access camera ([gocv](https://github.com/hybridgroup/gocv))
|
||||||
* `cv4` - build with `OpenCV` 4.x ([gocv](https://github.com/hybridgroup/gocv))
|
|
||||||
* `turbo` - build with `libjpeg-turbo` ([libjpeg-turbo](https://www.libjpeg-turbo.org/)) instead of native Go `image/jpeg`
|
* `turbo` - build with `libjpeg-turbo` ([libjpeg-turbo](https://www.libjpeg-turbo.org/)) instead of native Go `image/jpeg`
|
||||||
|
|
||||||
### Download
|
### Download
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
//go:build cv2 || cv4
|
|
||||||
// +build cv2 cv4
|
|
||||||
|
|
||||||
package camera
|
|
||||||
|
|
||||||
// Property identifiers.
|
|
||||||
const (
|
|
||||||
PropPosMsec = iota
|
|
||||||
PropPosFrames
|
|
||||||
PropPosAviRatio
|
|
||||||
PropFrameWidth
|
|
||||||
PropFrameHeight
|
|
||||||
PropFps
|
|
||||||
PropFourcc
|
|
||||||
PropFrameCount
|
|
||||||
PropFormat
|
|
||||||
PropMode
|
|
||||||
PropBrightness
|
|
||||||
PropContrast
|
|
||||||
PropSaturation
|
|
||||||
PropHue
|
|
||||||
PropGain
|
|
||||||
PropExposure
|
|
||||||
PropConvertRgb
|
|
||||||
PropWhiteBalanceU
|
|
||||||
PropRectification
|
|
||||||
PropMonocrome
|
|
||||||
PropSharpness
|
|
||||||
PropAutoExposure
|
|
||||||
PropGamma
|
|
||||||
PropTemperature
|
|
||||||
PropTrigger
|
|
||||||
PropTriggerDelay
|
|
||||||
PropWhiteBalanceV
|
|
||||||
PropZoom
|
|
||||||
PropFocus
|
|
||||||
PropGuid
|
|
||||||
PropIsoSpeed
|
|
||||||
PropMaxDc1394
|
|
||||||
PropBacklight
|
|
||||||
PropPan
|
|
||||||
PropTilt
|
|
||||||
PropRoll
|
|
||||||
PropIris
|
|
||||||
PropSettings
|
|
||||||
PropBuffersize
|
|
||||||
)
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
//go:build !cv2 && !cv4 && !android
|
|
||||||
// +build !cv2,!cv4,!android
|
|
||||||
|
|
||||||
package camera
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/korandiz/v4l"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Property identifiers.
|
|
||||||
const (
|
|
||||||
PropBrightness = v4l.CtrlBrightness
|
|
||||||
PropContrast = v4l.CtrlContrast
|
|
||||||
PropSaturation = v4l.CtrlSaturation
|
|
||||||
PropHue = v4l.CtrlHue
|
|
||||||
PropGain = v4l.CtrlGain
|
|
||||||
PropExposure = v4l.CtrlExposure
|
|
||||||
PropWhiteBalanceU = v4l.CtrlWhiteBalance
|
|
||||||
PropSharpness = v4l.CtrlSharpness
|
|
||||||
PropWhiteBalanceV = v4l.CtrlDoWhiteBalance
|
|
||||||
PropBacklight = v4l.CtrlBacklightCompensation
|
|
||||||
)
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
//go:build cv2 && !cv4
|
|
||||||
// +build cv2,!cv4
|
|
||||||
|
|
||||||
// Package camera.
|
|
||||||
package camera
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image"
|
|
||||||
"image/color"
|
|
||||||
"image/draw"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/disintegration/imaging"
|
|
||||||
"github.com/gen2brain/go-opencv/opencv"
|
|
||||||
"github.com/pbnjay/pixfont"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Camera represents camera.
|
|
||||||
type Camera struct {
|
|
||||||
opts Options
|
|
||||||
camera *opencv.Capture
|
|
||||||
frame *opencv.IplImage
|
|
||||||
}
|
|
||||||
|
|
||||||
// New returns new Camera for given camera index.
|
|
||||||
func New(opts Options) (camera *Camera, err error) {
|
|
||||||
camera = &Camera{}
|
|
||||||
camera.opts = opts
|
|
||||||
|
|
||||||
camera.camera = opencv.NewCameraCapture(opts.Index)
|
|
||||||
if camera.camera == nil {
|
|
||||||
err = fmt.Errorf("camera: can not open camera %d", opts.Index)
|
|
||||||
}
|
|
||||||
|
|
||||||
camera.SetProperty(PropFrameWidth, opts.Width)
|
|
||||||
camera.SetProperty(PropFrameHeight, opts.Height)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read reads next frame from camera and returns image.
|
|
||||||
func (c *Camera) Read() (img image.Image, err error) {
|
|
||||||
if !c.camera.GrabFrame() {
|
|
||||||
err = fmt.Errorf("camera: can not grab frame")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.frame = c.camera.RetrieveFrame(1)
|
|
||||||
if c.frame == nil {
|
|
||||||
err = fmt.Errorf("camera: can not retrieve frame")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
img = c.frame.ToImage()
|
|
||||||
|
|
||||||
switch c.opts.Rotate {
|
|
||||||
case 90:
|
|
||||||
img = imaging.Rotate90(img)
|
|
||||||
case 180:
|
|
||||||
img = imaging.Rotate180(img)
|
|
||||||
case 270:
|
|
||||||
img = imaging.Rotate270(img)
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.opts.Timestamp {
|
|
||||||
dimg, ok := img.(draw.Image)
|
|
||||||
if !ok {
|
|
||||||
err = fmt.Errorf("camera: %T is not a drawable image type", img)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pixfont.DrawString(dimg, 10, 10, time.Now().Format("2006-01-02 15:04:05"), color.White)
|
|
||||||
img = dimg
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetProperty returns the specified camera property.
|
|
||||||
func (c *Camera) GetProperty(id int) float64 {
|
|
||||||
return c.camera.GetProperty(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetProperty sets a camera property.
|
|
||||||
func (c *Camera) SetProperty(id int, value float64) {
|
|
||||||
c.camera.SetProperty(id, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes camera.
|
|
||||||
func (c *Camera) Close() (err error) {
|
|
||||||
if c.camera == nil {
|
|
||||||
err = fmt.Errorf("camera: camera is not opened")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.frame.Release()
|
|
||||||
c.camera.Release()
|
|
||||||
c.camera = nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !cv2 && !cv4 && !android
|
//go:build !opencv && !android
|
||||||
// +build !cv2,!cv4,!android
|
|
||||||
|
|
||||||
// Package camera.
|
// Package camera.
|
||||||
package camera
|
package camera
|
||||||
@@ -19,6 +18,20 @@ import (
|
|||||||
im "github.com/gen2brain/cam2ip/image"
|
im "github.com/gen2brain/cam2ip/image"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Property identifiers.
|
||||||
|
const (
|
||||||
|
PropBrightness = v4l.CtrlBrightness
|
||||||
|
PropContrast = v4l.CtrlContrast
|
||||||
|
PropSaturation = v4l.CtrlSaturation
|
||||||
|
PropHue = v4l.CtrlHue
|
||||||
|
PropGain = v4l.CtrlGain
|
||||||
|
PropExposure = v4l.CtrlExposure
|
||||||
|
PropWhiteBalanceU = v4l.CtrlWhiteBalance
|
||||||
|
PropSharpness = v4l.CtrlSharpness
|
||||||
|
PropWhiteBalanceV = v4l.CtrlDoWhiteBalance
|
||||||
|
PropBacklight = v4l.CtrlBacklightCompensation
|
||||||
|
)
|
||||||
|
|
||||||
// Camera represents camera.
|
// Camera represents camera.
|
||||||
type Camera struct {
|
type Camera struct {
|
||||||
opts Options
|
opts Options
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build cv4 && !cv2
|
//go:build opencv
|
||||||
// +build cv4,!cv2
|
|
||||||
|
|
||||||
// Package camera.
|
// Package camera.
|
||||||
package camera
|
package camera
|
||||||
@@ -16,6 +15,49 @@ import (
|
|||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Property identifiers.
|
||||||
|
const (
|
||||||
|
PropPosMsec = iota
|
||||||
|
PropPosFrames
|
||||||
|
PropPosAviRatio
|
||||||
|
PropFrameWidth
|
||||||
|
PropFrameHeight
|
||||||
|
PropFps
|
||||||
|
PropFourcc
|
||||||
|
PropFrameCount
|
||||||
|
PropFormat
|
||||||
|
PropMode
|
||||||
|
PropBrightness
|
||||||
|
PropContrast
|
||||||
|
PropSaturation
|
||||||
|
PropHue
|
||||||
|
PropGain
|
||||||
|
PropExposure
|
||||||
|
PropConvertRgb
|
||||||
|
PropWhiteBalanceU
|
||||||
|
PropRectification
|
||||||
|
PropMonocrome
|
||||||
|
PropSharpness
|
||||||
|
PropAutoExposure
|
||||||
|
PropGamma
|
||||||
|
PropTemperature
|
||||||
|
PropTrigger
|
||||||
|
PropTriggerDelay
|
||||||
|
PropWhiteBalanceV
|
||||||
|
PropZoom
|
||||||
|
PropFocus
|
||||||
|
PropGuid
|
||||||
|
PropIsoSpeed
|
||||||
|
PropMaxDc1394
|
||||||
|
PropBacklight
|
||||||
|
PropPan
|
||||||
|
PropTilt
|
||||||
|
PropRoll
|
||||||
|
PropIris
|
||||||
|
PropSettings
|
||||||
|
PropBuffersize
|
||||||
|
)
|
||||||
|
|
||||||
// Camera represents camera.
|
// Camera represents camera.
|
||||||
type Camera struct {
|
type Camera struct {
|
||||||
opts Options
|
opts Options
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCamera(t *testing.T) {
|
func TestCamera(t *testing.T) {
|
||||||
camera, err := New(Options{0, 0, 640, 480})
|
camera, err := New(Options{0, 0, 640, 480, false})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !cv2 && !cv4
|
//go:build !opencv
|
||||||
// +build !cv2,!cv4
|
|
||||||
|
|
||||||
// Package camera.
|
// Package camera.
|
||||||
package camera
|
package camera
|
||||||
|
|||||||
Reference in New Issue
Block a user