Halcon - Find Row coordinate of 2 points with smallest and biggest Col coordinates - row

I have a Region that can have any shape. (sample below)
I would need to find the ROW coordinates of the two points pointed with an arrow. (the most left and most right pixel coordinates of the region.)
I've managed to get the Col coordinates with smallest_rectangle1, but cannot find a way to extract the Row coordinates of given points.
How can this be done?

here the code you can use
* get the points of the region contour
get_region_contour (Region, Rows, Columns)
* sort the Columns
tuple_sort_index ( Columns, Indices)
* Left point
LeftIndex := Indices[0]
LeftRow := Rows[LeftIndex]
LeftColumn := Columns[LeftIndex]
* Right point
RightIndex := Indices[|Indices|-1]
RightRow := Rows[RightIndex]
RightColumn := Columns[RightIndex]

Related

how can i get the coordinates of vector from point abd it is orientation angle

image
Ihave two points with known coordinates
i (xi ,yi )
k(xk,yk)
I want to get a Vector fk in image containing a coordinate to find the angle between two vectors of orientation of target k (fk) and( ki). I know my beginning coordinates k , angle of rotation of target k and distance fom k to point i .
how can i get the coordinates of vector fk and angle beween the two vectors in written red

Determining Column and Row

This seems like such an easy thing to do, but I just can't figure it out... anyways, say I have a grid, let's say it's 100x100. Now let's say I have an element in position 34 of the grid, that being column 3 row 4. If I ONLY know the size of the grid (both x and y), how can I calculate the column and row it's currently in?
Visual example (5x5):
ooooo
ooooo
oowoo w is # position 12, but how do I calculate this?
ooooo
ooooo
r = position / width
c = position % width
Where r is the row the element is in, and c is the column the element is in, width is the width of the matrix
Assuming your positions start at (0,0)
int x = pos%width;
int y = pos/width;

Why? specific pixel processing should be process (h, w) not (w, h) or (x, y)

Some sample code about image processing using OpenCV give somethings like this:
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
if(pointPolygonTest(Point(i,j),myPolygon))
{
// do some processing
}
}
}
In the iteration, why we need to start from height and width? and also why the Point is store (height, width) so that is -> (y,x) ?
Ranges between [0..Height] and [0..Width] are maximum boundaries of your working area.
This code is testing which pixels of whole image are inside the polygon myPolygon.
The word "whole" means you should check all pixels of your image so you should iterate from 0 to height for Y, and iterate from 0 to width for X.
Actually here, the row/column convention is used to iterate over the whole image.
height = Number of Rows
width = Number of Columns
The image is being accessed row wise.The outer loop is iterating over rows of the image and the inner loop is iterating on columns. So basically i is the current row and j is the current column of the image.
The inner loop processes a complete row of the image.

Check if the line goes through wall on 2D map

I have 2d map and I want to check if line collides with any element. I need a function that can tell me if the line intersect any object on its way.
Take a look:
Red lines are not correct (function should return false), and green are (return true).
My collision map is map of boolean with 1 for wall and 0 for empty space.
How to this? I've read that I need to check if the line intersect any wall, but i have completely no idea how to do this on 2d map.
Thanx for any replies.
It depends on how your walls are represented.
If they are rectangle, then look for the line/segment intersection between your line and the 4 segments representing the rectangle.
If they are pixels, you can use the bresenham line algorithm to see if the pixels on the line are on these blocks.
If your walls are represented as line-segments you could test for intersection of line-segments as Paul Bourke describes: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
If your walls are represented as polygons you could clip your test line against the wall polygon and see if the clipping result is non-empty as Paul Bourke describes: http://local.wasp.uwa.edu.au/~pbourke/geometry/cliplinetopoly/
So, I imagined that your cells are squares... let say they're unit squares. So, if I have any coordinate, for a point like , which are floats or doubles, they are in cell .
you need to know in which cells are the endpoints of the line
walk straight from one endpoint to the other and for each cell, test if it's a wall or not
return false when a wall is found, true otherwise.
To walk from one endpoint to the other, you need to compute the delta of each axis (call delta_x and delta_y, those values are 'int' because we're talking cells here), i.e. the number of cells it goes on the vertical and on the horizontal. You take the largest of the two. You will use that largest value for your loop. Let say it's this value is D = max(delta_x, delta_y) and XX and YY are the coordinate of the cell of one endpoint.
float step = 1.0f / D;
float current_location = 0.0;
for (int i = 0; i <= D; ++i, current_location += step)
{
int cur_x = XX + current_location * delta_x;
int cur_y = YY + current_location * delta_y;
if (intersect_wall(cur_x, cur_y))
return false;
}
return true;
That's it... adapt this to your functions.

printing dots and boxes

I am writing a dots and boxes program for a class and have most everything ready to go except I am having trouble printing the grid.
Note: The grid can be any size from 2x2 to 9x9. A two by two grid must print like this to standard out:
a + + + //after some moves: a +-+ +
|P|
b + + + b +-+ +
c + + + c + + +
1 2 3 1 2 3
I have a data structure for the dots, edges, and boxes. and the grid object has a one dimensional vector for each class.
ie dots is a vector of all of the points on the grid,
edges is a vector of all the edges on the grid (Each edge has two dots)
boxes is a vector of all the boxes on the grid (each box has four edges)
the boxes have a enum for who owns the box Player or Computer
and the edges have an bool for if they are taken or not, and also a bool for if they are vertical or not.
I am getting confused when I am trying to print the grid since the grid can be multiple sizes.
Since (size) edges print on the even(horizontal) rows, and (size+1) on the odd(vertical).
I hope I am explaining this clearly.
Thanks!
Take your edges and lay it out in a sequence (a vector).
gridsize = 2 : hh vvv hh vvv hh
This is what you noticed with horizontal = 2 and vertical = size + 1.
Now figure out the algorithm to get the different values for the different edges. Here is how I stored the edges into a vector based on your example:
Your first (empty) 2x2 grid: 00 000 00 000 00
Your second 2x2 grid: 10 110 10 000 00
When I printed out the grid, I used rows and columns in for loops.
// I consider the (row, col) to be the box.
// Each row loop prints one horizontal line and (possibly) one vertical line.
// Access to the edge vector is based on this (row, col) pair.
for (int row = 0; row < size + 1; row++) /* +1 to draw the bottom line. */
{
if (row < size) /* Bottom most horizontal row not followed by vertical. */
for (int col = 0; col < size + 1; col++) /* +1 to draw rightmost line. */
}
The edge going from b1 to b2 is stored in position 5 (counting from 0, count the possible edges). How do you get this position?
You may want to stop here and figure the rest out yourself. I use pen and paper!
The edge from b1 to b2 (according to my algorithm) is part of the second row, first column (1, 0). When printing the horizontal edges, here's how to calculate the edge's position in the vector.
Horizontal edge: pos = (row * (size + size + 1)) + col
The edge from a2 to b2 is part of the first row, second column (0, 2). When printing the vertical edges you need to adjust it
Vertical edge: pos = (row * (size + size + 1)) + size + col
I implemented an HTML+JS version of this game using a 2D model of just cells (each with a list of edges) plus a separate 2D view model of all four things (h,v,c,d). See here for code snippets and a link to the full code and playable game: https://stackoverflow.com/a/30387118/1593924 .
That has the benefit of separating UI state/concerns, which have to do with rendering, from the 'real data' in the underlying model, which needs to understand quite different things:
that each cell 'touches' four edges and shares up to two of them with other cells,
how a cell becomes 'filled', and
how to handle players and extra turns when a player fills one (or two!) cells in a given turn.
In fact, the UI can render all four kinds of elements--vertices, v-edges, h-edges, and cells--as rectangles in a single grid, though the behavior attached to them is different between cells and edges (and omitted for vertices).