java - How to get pixels inside of a quadrilateral defined by four points in OpenCV? -
i'm new opencv, bit of luck , lot of time able hack code detects individual cells in chessboard so:
the image frame being stored in mat , corners being stored in matofpoint2f.
code show how i'm using matrices draw cells individually:
private void draw(final mat frame) { (int x = 0; x < board_size - 1; x++) (int y = 0; y < board_size - 1; y++) { final int index = x + y * board_size; final point topleft = cornerpoints.get(index); final point bottomleft = cornerpoints.get(index + board_size); final point topright = cornerpoints.get(index + 1); final point bottomright = cornerpoints.get(index + 1 + board_size); // left line imgproc.line(frame, topleft, bottomleft, debug_color); // right line imgproc.line(frame, topright, bottomright, debug_color); // top line imgproc.line(frame, topleft, topright, debug_color); // bottom line imgproc.line(frame, bottomleft, bottomright, debug_color); } }
how use 4 points (the corners of cells) rgb values of pixels inside of each quadrilateral?
create mask vertices. can use fillpoly that. iterate on pixels. if pixel(x,y) valid in mask, read rgb else continue. restrict pixel iteration range using extreme vertices.
Comments
Post a Comment