← All posts
Tag

opencv

24 posts · browse all tags

Fundamentals
·5 min read Intermediate

What Is Camera Calibration? Finding K from Photos of a Chessboard

Lesson 3 of Camera Geometry. Calibration measures a camera's focal length, image centre and lens bend by fitting the camera model to photos of a flat board whose corners are known. On OpenCV's thirteen chessboard photos: 0.41 px of reprojection error, a held-out photo that scores like the fitted ones, and a focal length anywhere from 520 to 568 px if only three photos are used.

camera-calibrationopencvgeometryfundamentals
Read more →
Fundamentals
·5 min read Intermediate

What Is PnP? Finding Where the Camera Is from Known Points

Lesson 4 of Camera Geometry. PnP finds where a calibrated camera stood and which way it faced from points whose positions are known and where they appear in one photo. On OpenCV's chessboard photos it returns the calibration's own pose to 0.00002°, four corners are enough for 0.27 px, and with five corners found wrong a plain fit moves the camera 2.5 squares where RANSAC moves it 0.008.

camera-calibrationopencvgeometryfundamentals
Read more →
Fundamentals
·8 min read Beginner

Find Every Ball on a Pool Table with OpenCV

The second OpenCV in Practice project: find the balls on a pool table by the one colour they are not, the cloth, and score the result ball by ball against a hand count on three photos. 29 of 41 found with 2 false alarms; 9 of the 12 misses are touching another ball.

opencvimage-processing
Read more →
Fundamentals
·6 min read Beginner

Fix a Badly Exposed Photo with OpenCV

The first OpenCV in Practice project: open a photo taken two stops too dark, read its histogram, try five ways to fix it, and measure each against a longer, better-exposed shot of the same scene (the target). Multiplying lands closest; the automatic fixes land furthest.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Brightness and Contrast in OpenCV

Brighten an underexposed photo two ways, adding a constant with cv2.add or multiplying with cv2.convertScaleAbs, and measure which lands closer to the target exposure: 18.0 against 9.1.

opencvimage-processing
Read more →
Fundamentals
·6 min read Beginner

Where Color Detection Fails in OpenCV

Score a colour-mask pipeline against a hand count on three pool table photos, fix the pockets and the shadows, and see what colour cannot fix: 27 of 41 balls found at first, 29 after the fixes, 9 of the 12 misses touching another ball.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Crop, Resize and Save an Image in OpenCV

Finish the fix: crop the colour chart with array slicing, shrink the photo with cv2.resize and INTER_AREA, and save it with cv2.imwrite, where the same picture is 54 KB as a JPEG and 276 KB as a PNG.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Gamma Correction in OpenCV with a Lookup Table

Build a 256-entry lookup table and apply it with cv2.LUT to brighten dark tones more than bright ones. Two stops dark, multiplying wins (9.1 against 10.7); three stops dark, gamma wins (13.9 against 15.1).

opencvimage-processing
Read more →
Fundamentals
·4 min read Beginner

Find the HSV Range of an Object in OpenCV

Read pixels of a pool table in HSV with cv2.cvtColor and find the range its cloth takes: its green value falls almost tenfold between the lit end and a shadow while its hue stays between 86 and 90.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Histogram Equalization and CLAHE in OpenCV

Try OpenCV's automatic contrast fixes, cv2.equalizeHist and CLAHE, on a dark photo with a bright lamp in it, and measure why they land further from the target exposure (30.6 and 35.5) than a plain multiplier (9.1).

opencvimage-processing
Read more →
Fundamentals
·4 min read Beginner

Find, Measure and Filter Contours in OpenCV

Find the outline of every blob in a mask with cv2.findContours, measure its area and roundness, and keep the ones shaped like a ball. On the pool table 11 of 14 blobs pass and the cue is rejected at roundness 0.12.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Image Histograms in OpenCV

Count how many pixels sit at each brightness with cv2.calcHist, draw the histogram, and read from it that the dark photo has 79.3% of its pixels in the bottom quarter and 7.8% burnt out.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Make a Color Mask with cv2.inRange in OpenCV

Turn an HSV range into a black-and-white mask with cv2.inRange, flip it with bitwise_not and apply it with bitwise_and. On the pool table one call marks 79.3% of the photo as cloth.

opencvimage-processing
Read more →
Fundamentals
·4 min read Beginner

Erode, Dilate, Open and Close a Mask in OpenCV

Clean a colour mask with morphology: erosion shrinks white areas, dilation grows them, opening removes specks and closing fills holes. On the pool table the mask goes from 59 blobs to 14.

opencvimage-processing
Read more →
Fundamentals
·3 min read Beginner

Open an Image and Read Its Pixels in OpenCV

Load a photo with cv2.imread, see that it is a grid of numbers with a shape and a type, and read one pixel and the mean brightness of a photo taken two stops too dark.

opencvimage-processing
Read more →
Fundamentals
·7 min read Beginner

An Image Is an Array: Shape, dtype, and Why OpenCV Hands You BGR

Lesson 1 of The Image as Data. One photograph, held three ways: a 24.7 MB mosaic of 12-bit counts, a 74.2 MB 16-bit development, and the 37.1 MB 8-bit array imread would give you. Two thirds of the numbers in that last one were never measured, adding 60 to a value of 207 gives 11, and a slice you write into changes the original.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Beginner

File Formats: What the Encoder Did Before You Read the Pixels

Lesson 6 of The Image as Data. A JPEG quality sweep costs almost nothing in PSNR and takes Canny's edge agreement from 0.949 to 0.895. Chroma subsampling saves 40% of the bytes for 0.09 of ΔE. And OpenCV and Pillow decode every JPEG here bit-for-bit identically; the disagreement is a 16-bit PNG, which Pillow silently opens as 8-bit.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Intermediate

Lens Distortion: Where the Straight-Line Model Actually Fails

Lesson 3 of the Image Formation unit. Real glass images the edges of the frame at a different scale from the centre, and the error climbs steeply with radius. Measured on OpenCV's calibration set: the top-left pixel of a 640x480 frame belongs 51.22 px from where the pinhole model puts it, and adding the Brown-Conrady terms drops the mean reprojection error of one view from 2.55 px to 0.170 px. Straightening it back costs field of view rather than pixels: 61.67 degrees becomes 67.32.

camera-calibrationopencvopticsfundamentals
Read more →
Fundamentals
·8 min read Beginner

The Image as Data: The Grid, the Integers, the Axes, and the File

The unit overview: what an array actually holds, where its samples sit, how finely each one is written down, what its three numbers mean, and what the encoder did before you read any of it. Measured on one photograph: two thirds of a colour image is interpolated, a 7.4-pixel ribbing returns as 96-pixel banding when you decimate by eight, bit depth stops buying anything at 9.4 bits, and the naive route from file to colour lands 9.54 ΔE from the light in the room.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Intermediate

Fisheye Models: When Correcting the Lens Stops Working

Lesson 4 of the Image Formation unit. The pinhole model puts a ray at f·tan θ, which runs to infinity at 90 degrees, and past about 120 degrees of field the stretch toward the edges makes it impractical. Fitted to the same 15 photographs of one fisheye lens, pinhole plus Brown-Conrady reaches 7.326 px RMS and Kannala-Brandt reaches 0.644 px. At 80 degrees the first model predicts a radius of -35,572 px, a sign flip; the second predicts 458.8 px, which is on the sensor.

camera-calibrationopencvopticsfundamentals
Read more →
Fundamentals
·16 min read Advanced

Structure from Motion, from Scratch: 47 Photos to a 3-D Temple in ~800 Lines of Python

How overlapping 2-D photos become 3-D points and camera poses: SIFT matching, the essential matrix, triangulation, PnP growth, and sparse bundle adjustment, built from scratch with OpenCV + SciPy. The pipeline registers all 47 Middlebury temple views at 0.25 px mean reprojection error, next to COLMAP's 0.30 px on the same images. Worked examples, three interactive labs, and the reconstruction growing image by image.

geometryopencvfundamentalsfeatures
Read more →
Fundamentals
·5 min read Intermediate

The Camera Matrix: K, [R|t] and P, Worked on a Real Chessboard

Lesson 2 of Camera Geometry. A camera is one 3×4 matrix: the focal lengths and image centre in K, where the camera stands in [R|t], and their product P, which sends any point of the world to a pixel. Worked on one corner of a chessboard in OpenCV's own calibration photos, checked against cv2.projectPoints, and taken apart again.

camera-calibrationopencvgeometryfundamentals
Read more →
Fundamentals
·8 min read Beginner

How 2D Convolution Works on Images: Kernels, Filters, and the Math, Interactively

2D convolution is the operation behind blur, sharpening, edge detection, and every CNN. Slide a kernel, multiply, sum: see it happen step by step in an interactive demo, apply real kernels to a live image, and get the math plus runnable OpenCV in Python and C++.

image-processingopencvfundamentals
Read more →
Fundamentals
·9 min read Beginner

Colour Spaces: Choosing Axes You Can Threshold

Lesson 4 of The Image as Data. A colour space is a choice of axes for the same three numbers, and the choice is what makes a question easy or impossible. Worked on one measured chart patch: RGB (149.8, 58.3, 34.0) becomes luma 82.8, hue 12.6 degrees stored as 6, and Lab (36.9, 37, 34), plus the five-line red detector that is brittle in RGB and robust in HSV.

image-processingopencvcolor-spacesfundamentals
Read more →