Data Structures and Algorithms/Cam Paint
62 / 67

01/2021Data Structures and Algorithms

Cam Paint

A webcam painting program in Java that tracks a colored object frame to frame and trails a brushstroke across a canvas.

╌╌╌╌

An interactive webcam painting program in Java. Point the camera at a colored object, click to sample its color, and the program tracks that object frame to frame, trailing a painted stroke across a persistent canvas.

CamPaint stores the clicked pixel as its targetColor and each frame hands the image to a RegionFinder, which grows regions by color. That finder flood fills outward from every matching seed, queuing a pixel's neighbors when its red, green, and blue channels each fall within maxColorDiff (45) of the target; a scratch image marks visited pixels, and any region smaller than minRegion (20) points is dropped as noise. largestRegion() returns the biggest surviving region as the brush.

Rather than track a single centroid, the program stamps every pixel of that largest region, in blue, into a separate painting layer, an ARGB BufferedImage that accumulates across frames. The live camera feed refreshes underneath, so the drawing stays put as the hand moves, and a keypress switches the display among the raw webcam, the regions recolored at random, and the painting alone.

References

  1. Project repository

╌╌ END ╌╌