lundi 4 juillet 2016

How to crop a part of image in the different matrix, but the matrix doesn't change its size in openCV.

I'm doing a project using openCV 2.4 ver. C++ I want to crop a part of image and save it in a different Matrix. Instead of getting a new single cropped image every loop, the cropped_image keeps previous images, and keeps building on next to the previous image. I wasn't sure what I did wrong.. Also this loops stops when n = 64 and m = 240. I also don't understand why.. Can anyone help me? openCV 2.4v C++ using namespace cv; using namespace std; original_image = imread("image.jpg",1); int n, m, cols_ss, rows_ss; int cols = 640; int rows = 480; cols_ss = 64 // arbitrary number; rows_ss = 48 // arbitrary number; Mat cropped_image; for (n = 0; n < cols - cols_ss; n = n + cols_ss) { for (m = 0; m < rows - rows_ss; m = m + rows_ss) { // initialize cropped_image as zeros. Mat cropped_image(cols_ss, rows_ss, CV_8UC1, Scalar::all(0)); // Crop a small part of an original_image to cropped_image. cropped_image = original_image(Rect(n, m, n + cols_ss, m + rows_ss)); } }

Aucun commentaire:

Enregistrer un commentaire