Scan and find the length and breadth of object from iPhone camera
I want to find the length, breadth and outside diameter of the object
My analysis so far:
Applied the multiple algorithms like Canny and Sobel to detect the edges of the object.
I converted a image into Matrix Array:
//Function that convert image to matrix array. - (cv::Mat)cvMatFromUIImage:(UIImage *)image { CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage); CGFloat cols = image.size.width; CGFloat rows = image.size.height;
cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels (color channels + alpha)
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to data
cols, // Width of bitmap
rows, // Height of bitmap
8, // Bits per component
cvMat.step[0], // Bytes per row
colorSpace, // Colorspace
kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault); // Bitmap info flags
CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image.CGImage);
CGContextRelease(contextRef);
return cvMat;
}
//Use function to create a matrix object.
cv::Mat cvImage = [self cvMatFromUIImage:image];
Then I apply the canny:
cv::Canny(grayImage, edges, m_cannyLoThreshold, m_cannyHiThreshold, m_cannyAperture * 2 + 1);
Same way I applied Sobel algorithm as well:
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
/// Gradient X
cv::Sobel( grayImage, grad_x, ddepth, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT );
cv::convertScaleAbs( grad_x, abs_grad_x );
/// Gradient Y
cv::Sobel( grayImage, grad_y, ddepth, 0, 1, 3, scale, delta, cv::BORDER_DEFAULT );
cv::convertScaleAbs( grad_y, abs_grad_y );
/// Total Gradient (approximate)
cv::addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, edges );
Now, I am separating the black and white pixels on the image. But every pixels that is looking black on device return some other pixel color.
What I have to do, separating the pixels from the image so that I get the actual height and width of object in image. Any suggestion ?
I have to detect the object in below image.
So, I'm not quite sure what the question you're asking is. What image are you trying to separate the black and white pixels on? Did you already try to use the threshold function? That turns the image into a binary image with only black and white pixels.
I'm not quite sure what the question you're asking is
There is hydraulic part that you can see in the above image, now we have to find the length, breadth and outside diameter of that hydraulic part.
What image are you trying to separate the black and white pixels on?
So, the approach is to convert above image into grayscale and separate the pixels of the object displayed in above image.
Did you already try to use the threshold function?
Regards to threshold function, I think I am using Harris Edge detection algorithm so it is already applied.
That turns the image into a binary image with only black and white pixels.
My concern is that if I used threshold function that you mention, my complete image turns into black color.