Package paletai.mapping
Class VidMap
java.lang.Object
paletai.mapping.VidMap
Handles homography transformations for video mapping with interactive calibration.
Provides UI for point adjustment and real-time perspective correction.
This class combines MathHomography calculations with Processing's
OpenGL rendering pipeline to create perspective-corrected video mappings. It
supports:
- Interactive calibration with draggable control points
- Real-time homography updates
- Serialization of mapping configurations
- Visual feedback during calibration
- Preview area integration for UI display
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanprocessing.core.PVector[]processing.core.PVector[]processing.core.PVector[]Normalized coordinates for shader (0-1 range)processing.core.PVector[]Pixel coordinates for Processing display -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassignToDisplay(int w, int h) Assigns this VidMap to a display with specific dimensions.voidcheckHover(float mousex, float mousey) Checks hover state for calibration points and image dragging.processing.opengl.PGraphics2DReturns the transformed media canvas after homography processing.voidHandles mouse release events for calibration interaction.voidmoveHoverPoint(float x, float y) Moves hover points or drags the entire image during calibration.processing.core.PVectorNormal2Pixel(processing.core.PVector in) Converts normalized coordinates back to pixel space.voidTurns off calibration mode.voidTurns on calibration mode.processing.core.PVectorPixel2Nornal(processing.core.PVector in) Converts pixel coordinates to normalized shader coordinates.voidrender(processing.core.PImage input) Renders a PImage with homography transformation applied.voidrender(processing.opengl.PGraphics2D input) Renders the input image with homography transformation applied.voidResets the homography to identity transformation.voidsetPreviewArea(float px, float py, float pw, float ph) Sets the preview area for calibration point display.voidToggles calibration mode on/off.voidToggles input checking mode for calibration.voidupdateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew) Updates the homography transformation from normalized coordinates.voidupdateHomographyFromPixel(processing.core.PVector[] xyPP, processing.core.PVector[] uvPP) Updates the homography matrix from pixel-space coordinates.
-
Field Details
-
xyN
public processing.core.PVector[] xyNNormalized coordinates for shader (0-1 range) -
uvN
public processing.core.PVector[] uvN -
xyP
public processing.core.PVector[] xyPPixel coordinates for Processing display -
uvP
public processing.core.PVector[] uvP -
checkInput
public boolean checkInput
-
-
Constructor Details
-
VidMap
Constructs a new VidMap instance. Initializes the homography shader, display buffers, and mathematical utilities.- Parameters:
p- The parent Processing appletname- Unique identifier for this mapping- See Also:
-
-
Method Details
-
assignToDisplay
public void assignToDisplay(int w, int h) Assigns this VidMap to a display with specific dimensions. Creates graphics buffers and configures the shader for the target resolution.- Parameters:
w- The width of the target displayh- The height of the target display- See Also:
-
setPreviewArea
public void setPreviewArea(float px, float py, float pw, float ph) Sets the preview area for calibration point display. Defines the screen region where calibration points and grids will be rendered.- Parameters:
px- Preview area x-coordinatepy- Preview area y-coordinatepw- Preview area widthph- Preview area height
-
resetHomography
public void resetHomography()Resets the homography to identity transformation. Initializes all points to the corners of the display and updates the homography matrix accordingly.- See Also:
-
updateHomographyFromPixel
public void updateHomographyFromPixel(processing.core.PVector[] xyPP, processing.core.PVector[] uvPP) Updates the homography matrix from pixel-space coordinates. Converts pixel coordinates to normalized coordinates and updates the transformation accordingly.- Parameters:
xyPP- Source points in pixel coordinatesuvPP- Destination points in pixel coordinates- Throws:
IllegalArgumentException- If arrays don't contain exactly 4 points- See Also:
-
updateHomography
public void updateHomography(processing.core.PVector[] xyNew, processing.core.PVector[] uvNew) Updates the homography transformation from normalized coordinates. Calculates the homography matrix and its inverse, then configures the shader with the transformed coordinates.- Parameters:
xyNew- Source points in normalized coordinates (0-1)uvNew- Destination points in normalized coordinates (0-1)- See Also:
-
toggleInput
public void toggleInput()Toggles input checking mode for calibration. Switches between input (source) and output (destination) point manipulation. -
render
public void render(processing.opengl.PGraphics2D input) Renders the input image with homography transformation applied. Processes the input through the homography shader and draws calibration visuals if calibration mode is active.- Parameters:
input- The input graphics to transform- See Also:
-
render
public void render(processing.core.PImage input) Renders a PImage with homography transformation applied. Wrapper method that converts PImage to PGraphics2D before processing.- Parameters:
input- The input image to transform- See Also:
-
getMediaCanvas
public processing.opengl.PGraphics2D getMediaCanvas()Returns the transformed media canvas after homography processing.- Returns:
- PGraphics2D containing the transformed output
-
Pixel2Nornal
public processing.core.PVector Pixel2Nornal(processing.core.PVector in) Converts pixel coordinates to normalized shader coordinates. Normalizes coordinates to 0-1 range and inverts Y-axis for shader compatibility.- Parameters:
in- Input point in pixel coordinates- Returns:
- Point in normalized coordinates (0-1, Y inverted)
-
Normal2Pixel
public processing.core.PVector Normal2Pixel(processing.core.PVector in) Converts normalized coordinates back to pixel space. Denormalizes coordinates and inverts Y-axis back to Processing coordinate system.- Parameters:
in- Input point in normalized coordinates- Returns:
- Point in pixel coordinates
-
toggleCalibration
public void toggleCalibration()Toggles calibration mode on/off. Enables or disables the interactive calibration interface. -
offCalibration
public void offCalibration()Turns off calibration mode. Disables the interactive calibration interface. -
onCalibration
public void onCalibration()Turns on calibration mode. Enables the interactive calibration interface. -
checkHover
public void checkHover(float mousex, float mousey) Checks hover state for calibration points and image dragging. Determines if mouse is hovering over calibration points or inside the transformable image area in the preview.- Parameters:
mousex- The current x-coordinate of the mousemousey- The current y-coordinate of the mouse- See Also:
-
moveHoverPoint
public void moveHoverPoint(float x, float y) Moves hover points or drags the entire image during calibration. Updates homography points based on mouse movement in preview space. Supports individual point movement and whole-image translation.- Parameters:
x- The current x-coordinate of the mousey- The current y-coordinate of the mouse- See Also:
-
mouseReleased
public void mouseReleased()Handles mouse release events for calibration interaction. Completes dragging operations and resets movement states.
-