Ask Your Question
0

copying smaller picture onto larger original frame

asked 2016-06-13 02:19:52 -0600

atv gravatar image

Hi! I'm trying to copy a smaller picture on to the larger frame. But i can't get it to work. It compiles fine but it does not show anything. My goal is to copy the recognised face onto the larger original frame.

//NEW
Mat face_resized;
//NEW
for(int i = 0; i < faces.size(); i++) {

    // Process face by face:
    Rect face_i = faces[i];
    // Crop the face from the image. So simple with OpenCV C++:
    Mat face = gray(face_i);

    // Resizing the face is necessary for Eigenfaces and Fisherfaces. You can easily
    // verify this, by reading through the face recognition tutorial coming with OpenCV.
    // Resizing IS NOT NEEDED for Local Binary Patterns Histograms, so preparing the
    // input data really depends on the algorithm used.
    //
    // I strongly encourage you to play around with the algorithms. See which work best
    // in your scenario, LBPH should always be a contender for robust face recognition.
    //
    // Since I am showing the Fisherfaces algorithm here, I also show how to resize the
    // face you have just found:
    //NEW
    face_resized=images[images.size()-1];
    //Mat face_resized=images[images.size()-1];
    //NEW

    cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);
    //model->setLabelsInfo(labelsInfo);
    // Now perform the prediction, see how easy that is:
    int prediction = model->predict(face_resized);
    double confidence = 0.0;
    model->predict(face_resized,prediction,confidence);

    // And finally write all we've found out to the original image!
    // First of all draw a green rectangle around the detected face:
    rectangle(original, face_i, CV_RGB(0, 255,0), 1);

And:

//NEW
cv::Rect roi = cv::Rect(50,50, face_resized.cols, face_resized.rows);
cv::Mat subview = original(roi);
subview.copyTo(original);
//NEW
while(tmp!=0) {
putText(original, tmp->name, Point(10,y),FONT_HERSHEY_PLAIN,1.0,CV_RGB(100,100,0),1.0);
y+=10;
tmp=tmp->next;}
}

imshow("face_recognizer", original);

(i only copied the relevant parts, can post more if needed).

Appreciate the help.

edit retag flag offensive close merge delete

Comments

Try something like this :

Rect r(0,0,subview.cols,subview.rows);
subview.copyTo(original(r));

I hope that subview will be copy at top left or original

LBerger gravatar imageLBerger ( 2016-06-13 13:55:33 -0600 )edit

I tried this, but still doesn't work..

    cv::Rect roi = cv::Rect(50,50, face_resized.cols, face_resized.rows);
cv::Mat subview = original(roi);
face_resized.copyTo(subview);

Compiles fine, doesn't crash, just doesn't show anything.

atv gravatar imageatv ( 2016-06-13 17:11:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-14 02:27:53 -0600

LBerger gravatar image

updated 2016-06-14 02:28:53 -0600

Something like this works

Mat m = imread("f:/lib/opencv/samples/data/lena.jpg", CV_LOAD_IMAGE_COLOR);
Mat logoOriginal = imread("f:/lib/opencv/samples/data/LinuxLogo.jpg",CV_LOAD_IMAGE_COLOR);
resize(logoOriginal,logoOriginal,Size(),0.5,0.5);
imshow("Lena",m);
imshow("Logo",logoOriginal);
waitKey();
Rect r(256-logoOriginal.cols/2,256-logoOriginal.rows/2,logoOriginal.cols,logoOriginal.rows);
logoOriginal.copyTo(m(r)); 
imshow("Lena+logo",m);
waitKey();

Image depth must be same.

PS There is tutorial somewhere and many post about this

edit flag offensive delete link more

Comments

Thanks, i'll try this. I searched for posts ofcourse, but couldn't find anything that was relevant or helped me. If you'd be so kind to give the link to the tutorial if you have it, that would be really good.

atv gravatar imageatv ( 2016-06-14 05:05:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-13 02:19:52 -0600

Seen: 1,899 times

Last updated: Jun 14 '16