2018-05-20 03:45:07 -0500 received badge ● Popular Question (source) 2015-09-29 05:28:38 -0500 received badge ● Student (source) 2014-04-14 05:55:22 -0500 asked a question Detecting squares in an image I found this square detection code online and I'm trying to understand it, does anyone understand what the line at the end does? it states: "gray = gray0 >= (l+1)*255/N;" Mat pyr, timg, gray0(image.size(), CV_8U), gray; // down-scale and upscale the image to filter out the noise pyrDown(image, pyr, Size(image.cols/2, image.rows/2)); pyrUp(pyr, timg, image.size()); vector > contours; // find squares in every color plane of the image for( int c = 0; c < 3; c++ ) { int ch[] = {c, 0}; mixChannels(&timg, 1, &gray0, 1, ch, 1); // try several threshold levels for( int l = 0; l < N; l++ ) { // hack: use Canny instead of zero threshold level. // Canny helps to catch squares with gradient shading if( l == 0 ) { // apply Canny. Take the upper threshold from slider // and set the lower to 0 (which forces edges merging) Canny(gray0, gray, 0, thresh, 5); // dilate canny output to remove potential // holes between edge segments dilate(gray, gray, Mat(), Point(-1,-1)); } else { // apply threshold if l!=0: // tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0 gray = gray0 >= (l+1)*255/N; }  2014-04-10 05:10:25 -0500 asked a question Object Recognition question please help Hi guys, I have wrote a object recognition code that is able to combine colour and shape tracking and track an object in a video based on these attributes. It works fine, however I'm having a slight issue with tracking two object of interest. so for example I am able to track a paper that is rectangle and red and this works fine, so if there another paper that is rectangle and blue or circle and red doesn't interfere with my tracking however if there is 2 papers that are both rectangle and red then the tracking will not work. Is there a way to counter this problem? to expand on this, the results i want to achieve is to track an object of interest in a video, however if a 2nd object of the same shape and colour was to appear in the video, i would like to ignore it and keep tracking the first object. 2014-03-27 11:00:48 -0500 asked a question How to detect the shape of an object whilst the object is moving? I have wrote the following shape code, but i'm having some difficulties regarding how it works. I want to be able to track the shape of the object whilst the object is moving, but at the moment the code below only tracks the shape of the object whilst the object is standstill and why whilst it is moving very slowly. Anyone knows any modifications i can make to the code to make it track objects moving quite fast? Thanks very much in advance. /** * Simple shape detector program. * It loads an image and tries to find simple shapes (rectangle, triangle, circle, etc) in it. * This program is a modified version of squares.cpp found in the OpenCV sample dir. */ #include #include #include #include #include #include #include #include #include #include #include #include #include /** * Helper function to find a cosine of angle between vectors * from pt0->pt1 and pt0->pt2 */ cv::Mat dst2; static double angle(cv::Point pt1, cv::Point pt2, cv::Point pt0) { double dx1 = pt1.x - pt0.x; double dy1 = pt1.y - pt0.y; double dx2 = pt2.x - pt0.x; double dy2 = pt2.y - pt0.y; return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10); } /** * Helper function to display text in the center of a contour */ void setLabel(cv::Mat& im, const std::string label, std::vector& contour) { int fontface = cv::FONT_HERSHEY_SIMPLEX; double scale = 0.4; int thickness = 1; int baseline = 0; cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline); cv::Rect r = cv::boundingRect(contour); cv::Point pt(r.x + ((r.width - text.width) / 2), r.y + ((r.height + text.height) / 2)); cv::rectangle(im, pt + cv::Point(0, baseline), pt + cv::Point(text.width, -text.height), CV_RGB(255,255,255), CV_FILLED); cv::putText(im, label, pt, fontface, scale, CV_RGB(0,0,0), thickness, 8); } int main() { //cvNamedWindow("Camera_Output", 1); //Create window CvCapture* capture = cvCaptureFromCAM(1); //Capture using any camera connected to your system while(1){ IplImage * img = cvQueryFrame(capture); cvSmooth(img, img, CV_GAUSSIAN,3,3); //show the original image //cvNamedWindow("Raw"); //cvShowImage("Raw",img); cv::Mat src(img); //cv::Mat src = cv::imread("/home/john/Desktop/basic-shapes.png"); //if (src.empty()) //return -1; // Convert to grayscale cv::Mat gray; cv::cvtColor(src, gray, CV_BGR2GRAY); // Use Canny instead of threshold to catch squares with gradient shading cv::Mat bw; cv::Canny(gray, bw, 0, 50, 5); // Find contours std::vector > contours; cv::findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); std::vector approx; cv::Mat dst = src.clone(); for (int i = 0; i < contours.size(); i++) { // Approximate contour with accuracy proportional // to the contour perimeter cv::approxPolyDP(cv::Mat(contours[i]), approx, cv::arcLength(cv::Mat(contours[i]), true)*0.04, true); // Skip small or non-convex objects if (std::fabs(cv::contourArea(contours[i])) < 500 ... 2014-02-12 09:00:55 -0500 asked a question Color and Shape tracking question, please help. I am trying to integrate a color detection code and a shape detection code into one, so instead of tracking the shape or color of a particular object, I would like to track both shape and color of the object using one code. is this achievable?