Documentation
¶
Overview ¶
Package hikrobot drives Hikrobot machine-vision cameras (GigE Vision, USB3 Vision and GenTL frame grabbers) through the vendor's MVS runtime, without cgo.
The runtime (MvCameraControl.dll, libMvCameraControl.so or .dylib) is loaded by Load at run time, so programs build on any platform and cross-compile without the MVS headers or a C toolchain. Capture works on Windows, Linux and macOS (amd64 and arm64; Windows amd64 only) wherever MVS is installed; elsewhere Load returns ErrUnsupported.
A minimal capture loop:
sdk, err := hikrobot.Load("") // default MVS install path
if err != nil { ... }
defer sdk.Close()
devices, err := sdk.Devices(0)
if err != nil || len(devices) == 0 { ... }
cam, err := sdk.Open(devices[0])
if err != nil { ... }
defer cam.Close()
_ = cam.SetEnumString("TriggerMode", "Off")
if err := cam.StartGrabbing(); err != nil { ... }
frame, err := cam.Grab(time.Second)
if err != nil { ... }
defer frame.Release()
img, err := cam.Image(frame) // *image.RGBA, debayered by the SDK
Frames are copied out of the SDK's buffer before Grab returns, so the SDK buffer is always given back. The copies come from a per-camera pool: call Release once you are done, and Retain before sharing a frame with another goroutine.
Index ¶
- Variables
- func DefaultRuntimePath() string
- type AccessMode
- type BayerQuality
- type Camera
- func (c *Camera) ClearImageBuffer() error
- func (c *Camera) Close() error
- func (c *Camera) Connected() bool
- func (c *Camera) ConvertTo(f *Frame, dst PixelType, buf []byte) ([]byte, error)
- func (c *Camera) Device() Device
- func (c *Camera) EnumSymbol(key string, value uint32) (string, error)
- func (c *Camera) Execute(key string) error
- func (c *Camera) GetBool(key string) (bool, error)
- func (c *Camera) GetEnum(key string) (EnumValue, error)
- func (c *Camera) GetEnumString(key string) (string, error)
- func (c *Camera) GetFloat(key string) (FloatValue, error)
- func (c *Camera) GetInt(key string) (IntValue, error)
- func (c *Camera) GetString(key string) (string, error)
- func (c *Camera) Grab(timeout time.Duration) (*Frame, error)
- func (c *Camera) Image(f *Frame) (*image.RGBA, error)
- func (c *Camera) LoadFeatures(path string) error
- func (c *Camera) OnException(fn func(Exception)) error
- func (c *Camera) OptimalPacketSize() (int, error)
- func (c *Camera) Preview(f *Frame, width int) (*image.RGBA, error)
- func (c *Camera) SaveFeatures(path string) error
- func (c *Camera) SetBayerQuality(q BayerQuality) error
- func (c *Camera) SetBool(key string, value bool) error
- func (c *Camera) SetEnum(key string, value uint32) error
- func (c *Camera) SetEnumString(key, symbol string) error
- func (c *Camera) SetFloat(key string, value float32) error
- func (c *Camera) SetGrabStrategy(s GrabStrategy) error
- func (c *Camera) SetImageNodeNum(n int) error
- func (c *Camera) SetInt(key string, value int64) error
- func (c *Camera) SetOutputQueueSize(n int) error
- func (c *Camera) SetResend(enable bool, maxPercent int, timeout time.Duration) error
- func (c *Camera) SetString(key, value string) error
- func (c *Camera) StartGrabbing() error
- func (c *Camera) StopGrabbing() error
- type Converter
- func (k *Converter) Close() error
- func (c *Converter) ConvertTo(f *Frame, dst PixelType, buf []byte) ([]byte, error)
- func (c *Converter) Image(f *Frame) (*image.RGBA, error)
- func (c *Converter) Preview(f *Frame, width int) (*image.RGBA, error)
- func (c *Converter) SetBayerQuality(q BayerQuality) error
- type Device
- type EnumValue
- type Error
- type Exception
- type FloatValue
- type Frame
- type GrabStrategy
- type IntValue
- type PixelType
- type SDK
- func (s *SDK) Accessible(d Device, mode AccessMode) bool
- func (s *SDK) Close() error
- func (s *SDK) Devices(transports Transport) ([]Device, error)
- func (s *SDK) Find(key string) (Device, error)
- func (s *SDK) NewConverter() (*Converter, error)
- func (s *SDK) Open(d Device) (*Camera, error)
- func (s *SDK) OpenMode(d Device, mode AccessMode) (_ *Camera, err error)
- func (s *SDK) Version() string
- type Transport
Constants ¶
This section is empty.
Variables ¶
var ( ErrTimeout = &Error{Code: 0x80000007} // MV_E_NODATA: no frame within the timeout ErrNotSupported = &Error{Code: 0x80000001} // MV_E_SUPPORT ErrParameter = &Error{Code: 0x80000004} // MV_E_PARAMETER ErrNodeNotFound = &Error{Code: 0x80000109} // MV_E_GC_NODE_NOT_FOUND ErrNodeAccess = &Error{Code: 0x80000106} // MV_E_GC_ACCESS: node not readable/writable now ErrAccessDenied = &Error{Code: 0x80000203} // MV_E_ACCESS_DENIED: opened by another program ErrBusy = &Error{Code: 0x80000204} // MV_E_BUSY: device busy or network down ErrDisconnected = &Error{Code: 0x80000211} // MV_E_DEV_DISCONNECT ErrBufferTooSmall = &Error{Code: 0x8000000A} // MV_E_NOENOUGH_BUF ErrUnsupportedType = &Error{Code: 0x80000500} // MV_E_SUPPORT_PIXEL_FORMAT )
Common SDK failures, for use with errors.Is.
var ErrClosed = errors.New("hikrobot: camera is closed")
ErrClosed is returned by calls on a closed Camera.
var ErrUnsupported = errors.New("hikrobot: MVS is not supported on this platform")
ErrUnsupported is returned by Load on platforms this package cannot load the MVS runtime on. Supported: windows/amd64, linux/amd64, linux/arm64, darwin/amd64 and darwin/arm64.
Functions ¶
func DefaultRuntimePath ¶
func DefaultRuntimePath() string
DefaultRuntimePath is where the MVS installer puts the runtime: the MvCameraControl framework on macOS; on Linux, under $MVCAM_COMMON_RUNENV (set by the installer) or /opt/MVS/lib.
Types ¶
type AccessMode ¶
type AccessMode uint32
AccessMode is how SDK.OpenMode claims the camera (MV_ACCESS_*).
const ( // AccessExclusive gives full control; other programs may only read the // control channel register. AccessExclusive AccessMode = 1 // AccessControl gives full control while letting other programs read // every register. AccessControl AccessMode = 3 // AccessMonitor opens read-only alongside a program that opened the // camera with AccessControl (an AccessExclusive holder refuses it). // GigE only. AccessMonitor AccessMode = 7 )
type BayerQuality ¶
type BayerQuality uint32
BayerQuality is the SDK's demosaicing method for Bayer conversions.
const ( BayerFast BayerQuality = 0 BayerBalanced BayerQuality = 1 BayerOptimal BayerQuality = 2 BayerOptimalPlus BayerQuality = 3 )
type Camera ¶
type Camera struct {
// contains filtered or unexported fields
}
Camera is an open device. Its methods are safe for concurrent use; Close waits for calls in progress, including a Grab blocked on its timeout.
func (*Camera) ClearImageBuffer ¶
ClearImageBuffer drops frames queued in the SDK.
func (*Camera) ConvertTo ¶
ConvertTo converts f to the dst pixel type (e.g. BGR8Packed for OpenCV) with the SDK, reusing buf when it is large enough.
func (*Camera) EnumSymbol ¶
EnumSymbol names one value of an enumeration node.
func (*Camera) GetEnumString ¶
GetEnumString reads an enumeration node's current symbol, e.g. "BayerGB8" for "PixelFormat".
func (*Camera) GetFloat ¶
func (c *Camera) GetFloat(key string) (FloatValue, error)
GetFloat reads a float node, e.g. "ExposureTime".
func (*Camera) Grab ¶
Grab waits up to timeout for the next frame and copies it out of the SDK. It returns ErrTimeout (via errors.Is) when no frame arrived. Release the frame when done with it.
func (*Camera) LoadFeatures ¶
LoadFeatures applies settings saved by SaveFeatures. Stop grabbing first.
func (*Camera) OnException ¶
OnException calls fn, on its own goroutine, for each asynchronous device event such as ExceptionDisconnected. A later call replaces fn.
func (*Camera) OptimalPacketSize ¶
OptimalPacketSize is the largest GigE packet the network path carries.
func (*Camera) Preview ¶
Preview converts f to RGBA scaled to width pixels wide (0 keeps the full size). Mono8 and 8-bit Bayer frames are downsampled before demosaicing, keeping whole colour cells, which makes a small live view much cheaper than converting the full frame.
func (*Camera) SaveFeatures ¶
SaveFeatures writes the camera's current settings to a file that LoadFeatures can apply later.
func (*Camera) SetBayerQuality ¶
func (c *Camera) SetBayerQuality(q BayerQuality) error
SetBayerQuality sets the demosaicing used by Image, Preview and ConvertTo.
func (*Camera) SetEnumString ¶
SetEnumString writes an enumeration node by symbol, e.g. SetEnumString("TriggerMode", "Off").
func (*Camera) SetGrabStrategy ¶
func (c *Camera) SetGrabStrategy(s GrabStrategy) error
SetGrabStrategy chooses which queued frame Grab returns. Set it before StartGrabbing.
func (*Camera) SetImageNodeNum ¶
SetImageNodeNum sets how many frame buffers the SDK allocates.
func (*Camera) SetOutputQueueSize ¶
SetOutputQueueSize bounds the queue kept by GrabLatest.
func (*Camera) SetResend ¶
SetResend controls GigE packet resend. maxPercent caps resend requests as a share of a frame's packets; timeout is how long to wait for a resent packet.
func (*Camera) StartGrabbing ¶
StartGrabbing starts acquisition. Configure trigger mode, pixel format and region first; most of those nodes are locked while grabbing.
type Converter ¶
type Converter struct {
// contains filtered or unexported fields
}
Converter runs the SDK's pixel conversion without a camera, e.g. on raw frames saved earlier and loaded with NewFrame. It is safe for concurrent use.
func (*Converter) ConvertTo ¶
ConvertTo converts f to the dst pixel type (e.g. BGR8Packed for OpenCV) with the SDK, reusing buf when it is large enough.
func (*Converter) Preview ¶
Preview converts f to RGBA scaled to width pixels wide (0 keeps the full size). Mono8 and 8-bit Bayer frames are downsampled before demosaicing, keeping whole colour cells, which makes a small live view much cheaper than converting the full frame.
func (*Converter) SetBayerQuality ¶
func (c *Converter) SetBayerQuality(q BayerQuality) error
SetBayerQuality sets the demosaicing used by Image, Preview and ConvertTo.
type Device ¶
type Device struct {
Transport Transport
Vendor string
Model string
Serial string
// UserName is the camera's user-defined name (DeviceUserID).
UserName string
// IP is the current address of a GigE camera; invalid otherwise.
IP netip.Addr
// MAC is set for GigE cameras.
MAC net.HardwareAddr
// contains filtered or unexported fields
}
Device describes one enumerated camera. Pass it to SDK.Open; a Device built by hand cannot be opened.
type EnumValue ¶
EnumValue is an enumeration node's current value and the values the camera accepts right now.
type Error ¶
Error is a failed MVS call. Code is the SDK's MV_E_* value; Op names the SDK function that returned it.
type Exception ¶
type Exception uint32
Exception is an asynchronous device event delivered to Camera.OnException.
type FloatValue ¶
type FloatValue struct{ Current, Min, Max float32 }
FloatValue is a float node's value and limits.
type Frame ¶
type Frame struct {
Width, Height int
PixelType PixelType
// Number is the camera's frame counter.
Number uint32
// LostPackets counts GigE packets missing from this frame.
LostPackets uint32
// HostTime is when the host received the frame.
HostTime time.Time
// DeviceTimestamp is the camera's tick counter at exposure (see the
// GevTimestampTickFrequency node for its rate).
DeviceTimestamp uint64
// contains filtered or unexported fields
}
Frame is one image copied out of the SDK. Its pixels are immutable and stay valid until the last owner calls Release. Grab hands you one ownership; Retain adds another, e.g. before passing the frame to another goroutine.
func NewFrame ¶
NewFrame copies data into a standalone frame, e.g. to replay a saved raw image through Camera.Image.
func (*Frame) Data ¶
Data returns the pixel bytes as the camera sent them. Do not modify them, and do not use them after your last Release.
type GrabStrategy ¶
type GrabStrategy uint32
GrabStrategy is how Grab picks frames from the SDK's queue (MV_GRAB_STRATEGY).
const ( // GrabOneByOne returns every frame in arrival order (SDK default). GrabOneByOne GrabStrategy = 0 // GrabLatestOnly drops everything but the newest frame. Use it for live // views where a slow consumer must not fall behind. GrabLatestOnly GrabStrategy = 1 // GrabLatest keeps the newest frames, up to SetOutputQueueSize of them. GrabLatest GrabStrategy = 2 // GrabUpcoming ignores queued frames and waits for the next one. GrabUpcoming GrabStrategy = 3 )
type IntValue ¶
type IntValue struct{ Current, Min, Max, Increment int64 }
IntValue is an integer node's value and constraints.
type PixelType ¶
type PixelType uint32
PixelType is a GigE Vision pixel format code (PixelType_Gvsp_* in the SDK's PixelType.h). Bits 16-23 hold the bits per pixel.
const ( Mono8 PixelType = 0x01080001 Mono10 PixelType = 0x01100003 Mono12 PixelType = 0x01100005 Mono16 PixelType = 0x01100007 BayerGR8 PixelType = 0x01080008 BayerRG8 PixelType = 0x01080009 BayerGB8 PixelType = 0x0108000A BayerBG8 PixelType = 0x0108000B BayerGR10 PixelType = 0x0110000C BayerRG10 PixelType = 0x0110000D BayerGB10 PixelType = 0x0110000E BayerBG10 PixelType = 0x0110000F BayerGR12 PixelType = 0x01100010 BayerRG12 PixelType = 0x01100011 BayerGB12 PixelType = 0x01100012 BayerBG12 PixelType = 0x01100013 RGB8Packed PixelType = 0x02180014 BGR8Packed PixelType = 0x02180015 RGBA8Packed PixelType = 0x02200016 BGRA8Packed PixelType = 0x02200017 YUV422 PixelType = 0x0210001F YUV422YUYV PixelType = 0x02100032 )
Common pixel types. Any other code the camera reports works too; it simply prints as hex.
func (PixelType) BitsPerPixel ¶
BitsPerPixel is the storage size of one pixel.
type SDK ¶
type SDK struct {
// contains filtered or unexported fields
}
SDK is a loaded MVS runtime. One per process is enough; it is safe for concurrent use.
func Load ¶
Load opens MvCameraControl.dll at path, or at DefaultRuntimePath when path is empty, and initializes it. Close it when done.
func (*SDK) Accessible ¶
func (s *SDK) Accessible(d Device, mode AccessMode) bool
Accessible reports whether d can be opened in mode right now. It is false while another program, such as the MVS client, holds the camera.
func (*SDK) Devices ¶
Devices lists the cameras reachable over the given transports, or over GigE and USB3 when transports is 0. Device order follows the SDK.
func (*SDK) Find ¶
Find returns the first device whose serial number, IP address, model or user-defined name equals key, ignoring case.
func (*SDK) NewConverter ¶
NewConverter creates a conversion handle that is not tied to any camera. Close it when done.
type Transport ¶
type Transport uint32
Transport is a transport-layer bit (MV_*_DEVICE). Combine them to choose what SDK.Devices enumerates.
const ( TransportGigE Transport = 0x00000001 TransportUSB3 Transport = 0x00000004 TransportCameraLink Transport = 0x00000008 TransportGenTLGigE Transport = 0x00000040 TransportGenTLCameraLnk Transport = 0x00000080 TransportGenTLCXP Transport = 0x00000100 TransportGenTLXoF Transport = 0x00000200 TransportGenTLVirtual Transport = 0x00000800 TransportGenTLXoC Transport = 0x00001000 )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
grab
command
Command grab captures frames from a Hikrobot camera and saves the last one as a PNG.
|
Command grab captures frames from a Hikrobot camera and saves the last one as a PNG. |
|
list
command
Command list prints the Hikrobot cameras MVS can see.
|
Command list prints the Hikrobot cameras MVS can see. |