Android: Drawing bounding box on object in bitmap - java

I have a black and white threshold bitmap. How will I detect and draw a bounding box around an object? For example:
The red box that is the box that I need to have drawn. The box is there because in this bitmap, the background is black, and inside the box is where the majority of the actual image (white) is. How would I get the app to detect and draw the bounding box?

Related

How to clip the black area from PNG image in java

I have a png image which contains black and transparency in the black area. I need to draw my other image, and retain the transparency area as is. What are all the possibilities we have in Java using graphic2d this is the PNG i am reffering

Java Graphics2D. Drawing scaled image on a retina display

I'm creating a 64x64 pixels VolitileImage, drawing some images and shapes on it (using drawImage, fillRect etc.), then I want to draw this image stretched up to 640x640 pixels. I expect to see the 64x64 matrix of 10x10 screen pixels squares. That's what I see on non-retina display. But when I try this on a retina-display I actually see 128x128 matrix of 5x5 squares.
Here's what I'm talking about:
Is there a way of "turning off" this behavior? Because what I need is to display 64x64 image stretched 10 times.
UPD:
Adding an compileable example: https://gist.github.com/miriti/651cb4b768cc5a076341
Each balack and white point is 1 pixel in a 64x64 image. Notice the difference between regular display and retina:

Is it Possible to Draw Transparent Boxes in GL11 Quads?

I'm wondering, can I draw transparent boxes in GL11 in JWJGL? I'm also wondering if I can draw these so I can have the screen turn red when you die but you can still see the background.
I used this for alpha/transparency:
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
You have to render everything behind the box first. Render the background before the box or you'll have an x-ray.

crop rectangle with certain border color and cetain background color JAVA

I have an Image with some rectangles inside it .. what i need is to crop only rectangles that have a red border and white background using (Java) or JavaCV.
for example i have an car image with license plate .. each letter at the license plate have red bordered rectangle around it and a white background.
what i am looking for is to crop each letter in a single image .. letters are identified by red bordered rectangle around each one and a white background.
Any suggestions?
Thanks
Change color space to HSV
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);
Get only hue channel:
cvSplit( imgHSV, h_plane, s_plane, v_plane, 0 );
Do the thresholding to find red color:
cvInRangeS(h_plane, cvScalar(x, x, x), cvScalar(x, x, x), imgThreshed);
x - range of red in HSV color model.
After this you will have white and black image, where white color is a red color on your original image (they should be of rectangle shape, as you said).
Then use cvFindContours function.
int contoursCont = cvFindContours( imgThreshed, storage,&contours,sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
To bound box (rectangle) use (for every contour):
CvBox2D box = cvMinAreaRect2( #current_contour#,
CvMemStorage* storage CV_DEFAULT(NULL))
To check the color of background calculate its histogram and check if values of bins are only 255 and 0 (they are values of white and black colors).
Hope, that will be useful!
You might try this:
Find a group of red pixels close to one another
Find all red pixels connected to these, bucket-fill style
Compute the bounding box of all the pixels found
Perhaps check whether the red pixels are all close to the rim of the bounding box
Check whether the interior of the box is mostly white
This should work as long as your boxes are not interrupted and do not overlap.

How to get the colour of a applet viewer pixel in Java?

I have drawn any picture, used Graphics 2D. How do I get the colour of a pixel at x, y? getPixelColor don't work, because this method get pixel from screen, not applet viewer coordinates.
Draw the picture to the Graphics of a BufferedImage
Draw the image to the Graphics2D.
To get the color of any pixel, call BufferedImage.getRGB(x,y) or variants (check the docs.).

Categories