Detect green laser dot
how to detect this green laser dot using android openCV
how to detect this green laser dot using android openCV
The image below has 4 sections for each step.
green channel using extractChannel(src, dst, 1)
threshold with threshold value 240
dilate with rect kernel of size 3x3 for 1 iteration
find contours and filter by excluding contours with area < 1000 and excluding contours with center y > 300
Hi chris thank for your valuable answer, after do some research on your steps in android finally i get the same output that you shown above and i am really thanks full for that , i need one more help from you that's
1) How i validate that green laser dot in drop inside tank outer boundaries or out of tank image boundaries ? 2) Tank is .png image inside imageview
Hey Bhavesh, I am not sure what the original tank image looks like. Is the background unique somehow? If so, you can take the center x,y of the remaining contour (laser dot) and look up the pixel in the image to check if it is on the tank or on the background. OpenCV Mat has an "at" method you can use to get a single pixel value.
Ok , i will explain my situation fist
1) Mobile full screen with fix size of imageview contain TANK image, 2) remaining screen white except tank 3) Imageview is rectangle but tank boundary was not fully fit with rectangle image So when laser dot drops inside TANK image border then should be print LOG otherwise nothing to do
How i can achieve this using openCV
Hey chrish i get other all thinks that i want accept one please explain or give me some code for your last two point (3,4).
3) dilate with rect kernel of size 3x3 for 1 iteration
4) find contours and filter by excluding contours with area < 1000 and excluding contours with center y > 300
The morphology looks something like:
Size kernelSize(3, 3); Mat kernel = getStructuringElement(MORPH_RECT, kernelSize); morphologyEx(srcImg, dstImg, MORPH_DILATE, kernel, Point(-1, -1), 1);
The contour finding looks like:
vector<vector<point>> contourList; findContours(srcImg, contourList, RETR_LIST, CHAIN_APPROX_NONE);
if (filterList.size() > 0) { for (auto& contour : contourList) { Point2f ctr = ContourFindCenter(contour); double area = contourArea(contour); Rect rect = boundingRect(contour); double ar = double(rect.width) / rect.height; if (area < 1000 && ...
more info here: https://docs.opencv.org/3.4/d4/d73/tu...
The morphology looks something like:
Size kernelSize(3, 3);
Mat kernel = getStructuringElement(MORPH_RECT, kernelSize);
morphologyEx(srcImg, dstImg, MORPH_DILATE, kernel, Point(-1, -1), 1);
The contour finding looks like:
vector<vector<Point>> contourList;
findContours(srcImg, contourList, RETR_LIST, CHAIN_APPROX_NONE);
if (filterList.size() > 0) {
for (auto& contour : contourList) {
Point2f ctr = ContourFindCenter(contour);
double area = contourArea(contour);
Rect rect = boundingRect(contour);
double ar = double(rect.width) / rect.height;
if (area < 1000 && .
..
more info here: https://docs.opencv.org/3.4/d4/d73/tu...
Please past full code so i will convert it in android,
Asked: 2019-05-08 09:19:20 -0600
Seen: 1,788 times
Last updated: May 10 '19
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
Installing Sample App / OpenCV Manager
How to detect square in a video using c++ and opencv?
OpenCV-2.4.2-android-sdk missing build.xml?
OpenCV libs on Real Android Device
Haar Cascade detecting only faces(no heads)?
Unresolved inclusions in OpenCV android tutorial 4.
build openCV for android, without CUDA
Extract the green channel. Threshold to only include high intensity areas (> 240 or so) Do a few rounds of dilation. Find contours and filter based on area and maybe aspect ratio
enter code here Imgproc.cvtColor(gray, hsv, Imgproc.COLOR_RGB2HSV); Core.inRange(hsv, new Scalar(45,100, 100), new Scalar(75,255,255), lowerRedRange); Imgproc.threshold(lowerRedRange, bw, 0, 255,Imgproc.THRESH_BINARY); // dilate canny output to remove potential // holes between edge segments Imgproc.dilate(bw, bw, new Mat(), new Point(-1, 1), 1);
enter code here // loop over all found contours for (MatOfPoint cnt : contours) { MatOfPoint2f curve = new MatOfPoint2f(cnt.toArray());
thats above is my code but not getting perfect dot of laser