|
Java Socket Programming with Hough_lines Ibrahim from United States [4 posts] |
16 year
|
How do I make sense of the data that I get from the variable HOUGH_LINES in Java? I'm using sockets and I get a 1024 value byte array, although the vast majority are empty and there are enough values to coordinate with x and y coordinates for the endpoints of each line. The data seems to be randomly put into the array, although most indices are multiples of 4.
|
|
|
HOUGH_LINES Anonymous |
16 year
|
Ibrahim,
You should get back a bunch of number separated by commas that reflect the lines of the hough_transform. For example, if you execute
telnet localhost 6060
<request><get_variable>HOUGH_LINES</get_variable></request>
assuming one Hough line you would get back
<response><HOUGH_LINES>53,246,548,249</HOUGH_LINES></response>
which returns the coordinate for one line as xstart,ystart -> xend, yend
Assuming you are using the Java wrapper class you should be getting back the sequence of numbers as a string.
Yes, the number are multiple of fours since you need a start and end coordinate of both X and Y numbers.
I'm not sure why you are getting back a 1024 byte array. Which API routine are you using or is this custom?
STeven.
|
|
|
Ibrahim from United States [4 posts] |
16 year
|
I was using the example Extension, and in the method ProcessVariables or something I added:
if (name.equalsIgnoreCase("HOUGH_LINES"))
{
System.out.println("Hough lines something");
for(int i=0;i<data.length;i++){
if(data[i]!=0) System.out.println("Position"+i+" holds "+data[i]);
}
}
and data is a byte array with 1024 values. The signature for the function is
int ProcessVariable(BufferedOutputStream writer, BufferedInputStream reader, ImageDataType imageData, String name, byte data[], int len) throws IOException
How can I parse this array into a proper array of points? The example has a method ByteToInt that converts a byte into an int and is used to get the width and height. Should I construct a new string using the byte array? That makes sense I guess. Thanks for the help.
|
|
|
Java byte to int code Anonymous |
16 year
|
Ibrahim,
Ok, you are using the extensions ... that is a little different.
What you have is a 4 byte per int situation. You need to convert the byte array to an int array using something like
int byteToInt(byte data[], int offset)
{
return (data[offset]&255)|((data[offset+1]&255)<<8)|((data[offset+2]&255)<<16)|((data[offset+3]&255)<<24);
}
int arr = new int[data.length>>2];
int j,i;
for (j=i=0;i<data.length;i+=4, j++)
arr[j]=byteToInt(data, i);
(note .. above is untested and uncompiled code!!)
which should give you the final 4 int array that we last talked about. Again this array should be a multiple of 4 and each 4 ints define a line segment.
STeven.
|
|