Skip to content

Instantly share code, notes, and snippets.

@olokobayusuf
Created October 26, 2018 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olokobayusuf/0c25f0cc086cc3dec7d958bed0d44ff2 to your computer and use it in GitHub Desktop.
Save olokobayusuf/0c25f0cc086cc3dec7d958bed0d44ff2 to your computer and use it in GitHub Desktop.
A script illustrating the recommended NatCam-OpenCV workflow.
byte[] pixelBuffer;
Mat previewMatrix;
void Start () {
// Start the camera preview
NatCam.Play(DeviceCamera.RearCamera);
// Register for preview events
NatCam.OnStart += OnStart;
NatCam.OnFrame += OnFrame;
}
void OnStart () {
// Display preview on a RawImage or plane?
...
// Initialize the preview buffer and matrix
pixelBuffer = new byte[NatCam.Preview.width * NatCam.Preview.height * 4];
previewMatrix = new Mat(NatCam.Preview.height, NatCam.Preview.width, CvType.CV_8UC4);
}
void OnFrame () {
// Update the preview data with the current preview frame
NatCam.CaptureFrame(pixelBuffer);
Utils.copyToMat (pixelBuffer, previewMatrix);
// Do OpenCV stuff
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment