Menu
Edge-detection output: white background with black outlines tracing the shapes in a photo

OpenCV Test App

An Android app for trying OpenCV image‑processing algorithms on the phone — from the camera or the gallery. Built as a sandbox while learning the OpenCV Android SDK.

The main screen has a spinner to choose an algorithm and a toolbar to load a picture. OpenCV 3.2.0 is bundled (Java bindings + native libraries) and loaded at runtime, so no separate OpenCV Manager install is needed. Targets compileSdk 25 / minSdk 15.

Canny Edge Detection

Two variants of the same operation — grayscale, then Imgproc.Canny(gray, out, 50, 150):

  • Canny Photo — on a still image, run on a background thread.
  • Canny Video — the same, per frame, on the live camera feed.
Edge-detection output: black outlines on white tracing the shapes in a photo

The edge‑detection stage, run here on a sample photo.

Document Scanner

Scanner.java finds a page in a photo and flattens it to a clean rectangle:

  1. Downscale to about 320×240 and Gaussian‑blur.
  2. Find the page outline — Canny, then findContours, and keep the largest‑area contour (assumed to be the page).
  3. Find the cornersHoughLinesP on that contour, then every pairwise line intersection that lands inside the frame; near‑identical points are merged.
  4. Reduce to the four points farthest from the centroid and order them top‑left / top‑right / bottom‑right / bottom‑left.
  5. WarpgetPerspectiveTransform + warpPerspective onto a rectangle sized from the detected edge lengths.

If fewer than four corners turn up it reports "Cannot detect perfect corners" and shows the points it did find. An alternative page‑vs‑background split using 2‑cluster k‑means (pick the cluster nearest pure white) is in the code but commented out.

Code

MainActivitymenu, camera/gallery, algorithm spinner
CannyPhotoActivity / CannyVideoActivityCanny on a still image / the live camera
ScannerActivityruns the document scanner and shows the result
Scannerthe pipeline: contours, Hough lines, corner sort, perspective warp

Notes

  • Old SDK (25) and OpenCV 3.2.0; the OpenCV API is largely unchanged in 4.x but the Gradle/SDK setup would need updating.
  • The scanner's Hough‑intersection corner finding is brittle on cluttered backgrounds — an approxPolyDP on the largest contour is usually steadier.
  • The vendored native libraries and OpenCV build output are committed, which makes the repo large.
Posted In:
Computer Vision