Ask Your Question

Raul Andrew's profile - activity

2016-03-15 05:16:45 -0500 received badge  Enlightened (source)
2016-03-15 05:16:45 -0500 received badge  Good Answer (source)
2013-12-11 07:15:24 -0500 answered a question Finding index of an image

Ati, I'm writing the solution as an answer so you can accept it for other users to see it.

You have to add the origin of the ROI as an offset:

row = (j/Dist.rows) + (j%Dist.rows) + roiOrigin.y;

col = j%Dist.cols + roiOrigin.x;

2013-12-11 05:52:32 -0500 commented question Finding index of an image

Ok, now I got it. If using a ROI before finding the contours is necessary, you can add to row and col the origin of the ROI as an offset: row = (j/Dist.rows) + (j%Dist.rows) + roiOrigin.y; col = j%Dist.cols + roiOrigin.x;

2013-12-11 03:54:24 -0500 commented question Finding index of an image

not sure about what you're trying to achieve. What do you mean when you say you want to find the index of the crop image? In the code you wrote it seems that you are going through each pixel of the image and if it isn't black you push the coordinates in the Index vector. In this way you'll obtain a vector with the coordinates of all the nonblack pixels in cropped. Is that what you want? If it is I think that you are pushing back the wrong coordinates. You should calculate row and col like this: row = (j/Dist.rows) + (j%Dist.rows); col = j%Dist.cols;

2013-12-08 01:56:43 -0500 received badge  Nice Answer (source)
2013-12-05 04:17:47 -0500 received badge  Teacher (source)
2013-12-05 02:48:33 -0500 answered a question how to set automatic threshold of image using opencv

Try looking into adaptive thresholding

void adaptiveThreshold( InputArray src, OutputArray dst,
                        double maxValue, int adaptiveMethod,
                        int thresholdType, int blockSize, double C );

This code shows you the difference between thresholding and adaptive thresholding:

#include <stdio.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char *argv[]) {
    Mat imgInput;
    Mat imgThreshold;
    Mat imgAdThreshold;

    imgInput = imread("yourImage.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    imgThreshold = Mat(imgInput.cols, imgInput.rows, IPL_DEPTH_8U, 1);
    imgAdThreshold = Mat(imgInput.cols, imgInput.rows, IPL_DEPTH_8U, 1);

    namedWindow("Input", CV_WINDOW_AUTOSIZE);
    namedWindow("Threshold", CV_WINDOW_AUTOSIZE);
    namedWindow("Adaptive Threshold", CV_WINDOW_AUTOSIZE);

    threshold(imgInput, imgThreshold,100,255,CV_THRESH_BINARY);
    //Adaptive Thresholding
    adaptiveThreshold(imgInput, imgAdThreshold, 255, 
                          CV_THRESH_BINARY, 75, 25);

    imshow("Input", imgInput);
    imshow("Threshold", imgThreshold);
    imshow("Adaptive Threshold", imgAdThreshold);
    return 0;
2013-12-04 16:37:40 -0500 received badge  Supporter (source)
2013-12-04 16:29:15 -0500 asked a question perspectiveTransform a set of points

Hello! I have two images, the first is distorted under perspective and the second is the rectification of a square in the previous image, obtained transforming it with the warpPerspective() function and a given 3x3 trasformation matrix M.

After working with the rectified image I've obtained a set of points that I'd like to transform back to the original image. These points are stored as Point2f or Point3f if I convert them to homogeneous coordinates. To my knowledge Opencv doesn't provide a function to directly transform a point or a set of points with a transformation matrix.

Do you have any suggestions on how I could do it? I saw similar questions and I found solutions like

std::vector<cv::point> inPts, outPts; inpPts.push_back(cv::Point(3, 5)); perspectiveTransform(inPts, outPts, homography);

but it doesn't seem to work. I was thinking of using M.inv() to map back the points in the first image, is that correct?

Thank you in advance.