Skip to content

Instantly share code, notes, and snippets.

View olokobayusuf's full-sized avatar

Yusuf Olokoba olokobayusuf

View GitHub Profile
...
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(index, cameraInfo);
...
public static void RotateImage (Color32[] dst, Color32[] src, int width, int height, byte orientation) {
int rotation = ..., mirror = ...; // Extract the rotation and mirror bits from the orientation byte
Func<int, int> kernel = null;
switch (rotation) {
case 0: kernel = i => i; break; // 0
case 1: kernel = i => height * (width - 1 - i % width) + i / width; break; // 90
case 2: kernel = i => src.Length - 1 - i; break; // 180
case 3: kernel = i => src.Length - 1 - (height * (width - 1 - i % width) + i / width); break; // 270
}
for (int i = 0; i < src.Length; i++) dst[kernel(i)] = src[i]; // Reposition the pixels // Memory accesses for the destination buffer are all over the place
Camera.Parameters params = camera.getParameters();
if (params.getMaxNumMeteringAreas() > 0 && params.getMaxNumFocusAreas() > 0) {
...
LogVerbose("Attempting to focus camera " + index + " at (" + Math.round(x * 100) / 100f + ", " + Math.round(y * 100) / 100f + ")");
} else {
...
LogError("Camera "+index+" does not support focus"); // Control only reaches here when the check above fails
}
void SwitchCamera () {
var newCamera = ...;
// Set the new active camera
NatCam.Camera = newCamera;
}
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using Lean.Touch;
public class LeanFocuser : MonoBehaviour {
public FocusMode focusMode = FocusMode.AutoFocus | FocusMode.TapToFocus;
public bool IsTracking {get; private set;}
using UnityEngine;
using NatCamU.Core;
public class CheckCameras : MonoBehaviour {
void Start () {
foreach (var camera in NatCam.Cameras) if (camera) {
Debug.Log("Found a camera with facing: " + camera.Facing);
return;
}
@olokobayusuf
olokobayusuf / Permutations.java
Last active June 8, 2017 21:25
Permutations in Java
import java.util.Arrays;
import java.util.ArrayList;
public final class Permutations {
private static final int input[] = {1, 2, 3};
public static void main (String args[]) {
// Permute
ArrayList<int[]> permutations = permute(input);
@olokobayusuf
olokobayusuf / ForceRearCamera.cs
Last active June 10, 2017 01:20
Example showing how to explicitly set NatCamBehaviour members from code before starting the camera
using NatCamU;
public class ForceRearCamera : NatCamBehaviour {
public override void Start () {
// Force the rear camera
facing = Facing.Rear;
// Carry on
base.Start();
}
@olokobayusuf
olokobayusuf / DrawLine.cs
Created July 13, 2017 00:14
This is an example script that demonstrates using the new OpenCVBehaviour in NatCam Professional 1.6.
using UnityEngine;
using NatCamU.Core;
using NatCamU.Professional;
using OpenCVForUnity;
public class DrawLine : OpenCVBehaviour {
public override void OnMatrix () {
// Draw a diagonal line on our image
Imgproc.line(matrix, new Point(0, 0), new Point(matrix.cols(), matrix.rows()), new Scalar(255, 0, 0, 255), 4);
@olokobayusuf
olokobayusuf / RecordRelease.cs
Created July 23, 2017 16:55
NatCam test case for recording videos across calls to NatCam.Release. Get NatCamTest in the NatCam Test Suite repo on my GitHub.
/*
* NatCam Test Suite
* Copyright (c) 2017 Yusuf Olokoba
*/
namespace NatCamU.Tests {
using UnityEngine;
using Core;
using Professional;