LoginSignup
3
3

More than 5 years have passed since last update.

OpenCVで任意の短形を切り取った画像を返す関数

Posted at

画像のファイルパスと切り取る短形を受け取ると、切り取った画像を返す関数。
切り取った画像の解放は後でやらないといけない。

cutImage
// 画像を指定範囲で切り取って返す
IplImage *cutImage(char* name,CvRect cutRect){
  IplImage *dst_img,*cutImage;
  dst_img = cvLoadImage (name, CV_LOAD_IMAGE_COLOR);
  // 注目範囲を設定
  cvSetImageROI (dst_img, cutRect);
  cutImage = cvCreateImage(cvGetSize(dst_img),dst_img->depth,dst_img->nChannels);

  // 注目した領域をコピーして保持
  cvCopy(dst_img, cutImage, NULL);
  cvResetImageROI(dst_img);

  dst_img = cvCloneImage(cutImage);

  return dst_img;
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3