0

I am working on a project based on Template Matching using OpenCV.

How can I make an array of images ?

cv::Mat ref_temp[7]; // Array Declaration as we do in c/c++
cv::Mat image = cv::imread("ref.jpg",1);  
cv::Mat ref_image;

image.copyTo( ref_image);   

cv::Mat ref_temp(1) =(ref_image, cv::Rect(550,85, 433, 455));
cv::Mat ref_temp[2] =(ref_image, cv::Rect(1042,85,433, 455));
cv::Mat ref_temp[3] =(ref_image, cv::Rect(1528,85,433, 455));
cv::Mat ref_temp[4] =(ref_image, cv::Rect(65, 1010, 423, 442));
cv::Mat ref_temp[5] =(ref_image, cv::Rect(548, 1010, 423, 442));
cv::Mat ref_temp[6] =(ref_image, cv::Rect(1025, 1010, 423, 442));
cv::Mat ref_temp[7] =(ref_image, cv::Rect(1529, 1010, 423, 442));

I am not sure I am doing it in a right way. Please help me.

3
  • Can you tell us more about what you want to accomplish? Are you getting compiler or runtime errors? If so, what do those errors say? I'm not familiar with Template Matching. Do you want to create an array of images that are scaled to different sizes:? Commented Jul 20, 2014 at 0:35
  • Actually, I am using one reference image named as ref_image and then I am taking the reference templates from that image (as per the co-ordinates). Now I have 8 different images cut from the reference image. I want to store these images in a array. Commented Jul 20, 2014 at 0:43
  • @ahoffer : I am not familiar with the opencv coding methods. Commented Jul 20, 2014 at 0:51

1 Answer 1

1

First, create a region of interest (ROI) from ref_image, where the top-left corner of the ROI is (550, 85), and the width and height is 443 & 455:

cv::Mat ref_img_roi(ref_image, cv::Rect(550, 85, 433, 455);

Next, assign the the ROI to your image array:

ref_temp[0] = ref_img_roi;

Now, the ref_temp[0] references to the region specified in ref_img_roi of theref_image.

In your code, the usage of the C++ array is incorrect. You don't have to put cv::Mat when using the ref_temp. And, the index of array should be 0 ~ 6. The following code will work:

cv::Mat ref_temp[7];
cv::Mat image = cv::imread("ref.jpg",1);  
cv::Mat ref_image;
image.copyTo( ref_image);

ref_temp[0] = cv::Mat(ref_image, cv::Rect(550, 85, 433, 455));
ref_temp[1] = cv::Mat(ref_image, cv::Rect(1042, 85, 433, 455));
ref_temp[2] = cv::Mat(ref_image, cv::Rect(1528, 85, 433, 455));
ref_temp[3] = cv::Mat(ref_image, cv::Rect(65, 1010, 423, 442));
ref_temp[4] = cv::Mat(ref_image, cv::Rect(548, 1010, 423, 442));
ref_temp[5] = cv::Mat(ref_image, cv::Rect(1025, 1010, 423, 442));
ref_temp[6] = cv::Mat(ref_image, cv::Rect(1529, 1010, 423, 442));
Sign up to request clarification or add additional context in comments.

1 Comment

user3207049 - if you did reall appreciated it, you would have upvoted the answer of @mcchu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.