I need to detect shape in a .bmp in java. The image can have any shape oval, ellipse or a circle. It'll be like a circle with black boundaries on a white background. I tried using boofCV but couldn't get the desired result. Any other library which will help in this case.
Related
I have two images, one that is a monochrome one which is a mask and another one with full color. What I need to do is find the CGRect of the mask (white pixels) in the other full color one.
What I did is to first find the contour of the mask using the Vision framework. Now, this returns a CGPath which is normalised. How can I translate this path into coordinates to the other image? Both have been scaled the same way to make them the same size so the translation should be "easy" but I can't figure it out.
Even though I am using OpenCVForUnity, I don't think the problem is about the wrapper, but OpenCV in general.
I basically just use this scipt (which is based on the native c++ aruco implementation) to detect contours by calling the FindRectangularContours function. If the markers are aligned with the camera i.e. parallel to the image border, then most of the rectangles are not detected, but when I rotate the camera they are detected.
The gray scale image is just to show the contours. The found contours are then outlined green.
I have an random shape bitmap cut out by user. I want to fade out its borders i.e. contours, so as to make it appear smooth. What should I do? To get the borders and color of every pixel in bitmap, I am traversing it pixel by pixel. It takes long time, still I am ok with it. Is openCV my only option? If yes, can anybody point me towards any tutorial or suggestion for logical approach?
You can just run a smoothing filter on your shape.
In opencv you can use the blur fnnction or gaussainBlur. Look at http://docs.opencv.org/2.4/doc/tutorials/imgproc/gausian_median_blur_bilateral_filter/gausian_median_blur_bilateral_filter.html.
You don't have to use opencv but i think it would be easier and faster.
If you still don't want can use any other code that implement smoothing an image.
In case you just want to effect the border pixels do the following:
Make a copy of the original image
Filter the entire image.
Extract the border pixel using opencv findContours.
Copy from the blurred image only the pixels in the border and in there neighborhood and copy them to the copy you did in step 1.
I am a beginner in OpenCV. I know C++ and Android Programming. I have decided to shift on OpenCV.
In my project, Using OpenCV I am detecting a red color ball through camera and getting its coordinates. Using these coordinates, I want to draw the same line or shape on a separate white image. For example, if the use user moves ball to write the alphabet W in the air, and I have received all the coordinates of ball position, I want to draw W on the separate image. I am not asking for code, but little help and guidance.
Thanks in advance.
If you have the coordinates it is easy. First create your cv::Mat and set it all white.
cv::Mat image;
image.setTo(cv::Scalar(255,255,255));
Then if you have the begin and the end coordinates you can draw a line using opencv line function.
cv::line(image, cv::Point(initial_coords.x, initial_coords.y), cv::Point(end_coords.x, end_coords.y), cv::Scalar(0,0,255));
Finally to do the w use puttext function
cv::putText(image, "text", cv::Point(coords.x, coords.y), cv::FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(255), 3,8);
If you need to erase the window before adding new things use again the
image.setTo(cv::Scalar(255,255,255));
In OpenCV, i know how to draw circles, but is there a way to get back all the points that makeup the circle? I hope I dont have to go through calculating contours.
Thanks
If you know how to draw the circle,
Create a black image with the same size of as that of original image
Then draw the circle on the black image with white color
Now in this black image, check the points which are white
If you are using Python API, you can do as follows :
import numpy as np
import cv2
img = np.zeros((500,500),np.uint8)
cv2.circle(img,(250,250),100,255)
points = np.transpose(np.where(img==255))
You can do similar thing to the answer implemented in python in C/C++
If you know how to draw the circle,
Create a black image with the same size of as that of original image
Then draw the circle on the black image with white color
Now instead of checking which pixels have certain value you can find a contour (represented as vector of points) of the circle's edge.
To do this you can use OpenCV's findContours function which will give you the points on the circles edge.
Actually the background doesn't have to be black and the circle white, but the background should be plain and the circle should have different color than background.