Ask Your Question

Restomix's profile - activity

2016-04-03 02:01:56 -0600 commented question Combining a matrix image.

You are right, thank.But how to check whether they intersect?

2016-04-02 16:47:04 -0600 asked a question Combining a matrix image.


I want to combine two images into one.
Combine only image, without background(.png)
Paste the image at coordinates.

If somewhere pixels overlap with the previous picture, inform( return -1;)

EXAMPLE:

Image1(a matrix):
101
001
Image1(a matrix):
01
00
Image1+Image2(through the point A(0;0))
111
001
Image1+Image2(through the point C(1;0))
Error.Because, images intersect in point X(3;0)
Help please. I will be very grateful. I am Newbie in openCv, it's all that I have done:

  Mat stamps(char* name)
    {
   Mat src = imread(name, 1);
    Mat dst;//(src.rows,src.cols,CV_8UC4);
    Mat tmp, alpha;

    cvtColor(src, tmp, CV_BGR2GRAY);
    threshold(tmp, alpha, 100, 255, THRESH_BINARY);

    Mat rgb[3];
    split(src, rgb);

    Mat rgba[4] = { rgb[0], rgb[1], rgb[2], alpha };
    merge(rgba, 4, dst);
    return dst;
    }
    int main()
    {
    Mat image1=imread("...name");//in
    Mat image2 =stamps("....name");//from
    int x=0,y=0;
    image2.copyTo(dst.rowRange(y, y + image2.size().height).colRange(x, x + image2.size().width));
    }

//result with background image description

2016-02-10 11:25:52 -0600 commented answer Search small images on one images.

Beautiful code.Thank you again)

2016-02-08 13:32:28 -0600 commented answer Search small images on one images.

Thank you very much you are very good person. Sorry for importunity(will not be repeated). I will work with your algorithm, he best for me.I am exporting images from PDF.Maybe I export a different look for the best option.

2016-02-08 07:52:53 -0600 received badge  Student (source)
2016-02-07 11:04:46 -0600 asked a question Extracts the small images.

I try search small images in big a image.But it does not always work correctly.For example I have two identical images but their quality is different.C:\fakepath\Page-1.jpgC:\fakepath\Page-2.jpg How can I improve the search algorithm to each selected image corresponding values (coefficients).

Mat::ones(Size(12, 12), CV_8UC1);//clear a bit, I have change Depending on the image
dilate(bw, bw, kernel);
erode(bw, bw, kernel);
//ignore small contour ... may be is noise 
    if (contours[idx].size() < 40) continue;//40, I have change Depending on the image

Maybe I need another filter cleaning image or threshold.

    void Main_ExtractStamps(char* name)
{
    Mat img, src, dst, gray, bw;
img = imread(name);
src = img;

src.copyTo(dst);
//convert to gray scale
cvtColor(src, gray, CV_BGR2GRAY);
threshold(gray, bw, 0, 255, THRESH_BINARY | THRESH_OTSU);
gray = bw;
//Mat a;bilateralFilter(gray,a, 20, 1, 80);bw = a;
// clear a bit
Mat kernel = Mat::ones(Size(12, 12), CV_8UC1);//Change 
dilate(bw, bw, kernel);
erode(bw, bw, kernel);
Mat copyMask(bw.size(), bw.type());
//detect outer contour of the stamps
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
vector<Rect>  stampsRect;
vector<RotatedRect>  stampsRectRotated;
findContours(bw, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
// iterate through all the top-level contours,
int idx = 0;
for (; idx >= 0; idx = hierarchy[idx][0])
{
    //ignore small contour ... may be is noise 
    if (contours[idx].size() < 40) continue; //Change
    //store contour boundingRect
    stampsRect.push_back(boundingRect(contours[idx]));
    stampsRectRotated.push_back(minAreaRect(contours[idx]));
    //prepare the copy mask 
    drawContours(copyMask, contours, idx, 255, CV_FILLED, 8, hierarchy);
    //show selected contours 
    drawContours(dst, contours, idx, Scalar(0, 0, 255), 5, 8, hierarchy);
}
Mat rot_mat(2, 3, CV_32FC1);
RotatedRect rr;
for (idx = 0; idx < stampsRect.size(); idx++)
{
    RotatedRect  rr = stampsRectRotated[idx];
    Rect rect = stampsRect[idx];
    Point center(rect.width / 2, rect.height / 2);
    //create an empty image with a default background
    Scalar bkg(0, 0, 0);
    Mat stamp(rect.height, rect.width, src.type(), bkg);
    //copy the stamp from source using a mask
    src(rect).copyTo(stamp, copyMask(rect));
    //straighten
    if (rr.angle != 0)
    {
        //rot_mat = getRotationMatrix2D(center, 90 + rr.angle, 1);
        //warpAffine(stamp, stamp, rot_mat, stamp.size());
    }
    imwrite("../img/Stamp" + std::to_string(idx) + ".jpg", stamp);
    imshow("Stamp" + to_string(idx), stamp);
}
imshow("Bin", bw);
imwrite("../img/StampDST..jpg", dst);
//imshow("DST", dst);
const char* pzOriginalImage = "Result Image";
namedWindow(pzOriginalImage, CV_WINDOW_AUTOSIZE);
resize(dst, dst, cvSize(1000, 800));
imshow(pzOriginalImage, dst);

waitKey();

}

Help me, I will be very thankful. The result is not very good: image description

2016-02-07 02:41:42 -0600 received badge  Enthusiast
2016-02-05 15:56:13 -0600 commented answer Search small images on one images.

I found the reason is the image quality(pixels) of the image.

// clear a bit
Mat kernel = Mat::ones(Size(3,3), CV_8UC1);//3,3 need change
//ignore small contour ... may be is noise 
    if (contours[idx].size() < 20) continue;//20 need change

How to choose an option, depending on the image quality?Thank you in advance.
2016-02-05 14:20:01 -0600 commented answer Search small images on one images.

This algorithm does not work for http://answers.opencv.org/upfiles/145... reason?and for .jpg.Help me please, I will be very grateful to you.

2016-02-03 13:20:36 -0600 received badge  Scholar (source)
2016-02-03 13:20:28 -0600 commented answer Search small images on one images.

Thank you again, I understand.

2016-02-03 11:44:34 -0600 commented answer Search small images on one images.

very very thank you). If picture is not in the form of a square?How then cut small image?

2016-02-03 07:48:04 -0600 received badge  Supporter (source)
2016-02-02 10:38:23 -0600 commented question Search small images on one images.

Random. Example added on top.

2016-02-02 10:36:31 -0600 received badge  Editor (source)
2016-02-02 09:58:12 -0600 asked a question Search small images on one images.

I have a picture in which there are small pictures. They are separated by black background.Further I save this small pictures.Please help me i am new in OpenCV.I know that I have to find edges.How then me divided small pictures? Give an example or literature.I work c#/c++.Thank you very much.Image:image descriptionC:\fakepath\1.pngC:\fakepath\test222.png