Precautions for iplimage> imagedata assignment in opencv

Source: Internet
Author: User

When the original image detects the face area, a problem occurs when assigning the face area to an image created using the cvcreateimage function.

Shows the problem image. The original code is as follows:

[CPP]
View plaincopyprint?
  1. Cvsize tmpsize;
  2. Tmpsize. width = width;
  3. Tmpsize. Height = height;
  4. Iplimage * tmpimg = cvcreateimage (tmpsize, ipl_depth_8u, 1 );
  5. Int M = starty;
  6. For (INT I = 0; I
  7. {
  8. Int n = startx;
  9. // Int widthstep = tmpimg-> widthstep;
  10. For (Int J = 0; j <width; j ++)
  11. {
  12. * (Tmpimg-> imagedata + I * <span style = "color: RGB (255, 0, 0);"> width </span> + J) =
  13. * (Image-> imagedata + M * image-> <span style = "color: RGB (255, 0, 0);"> width </span> + n );
  14. N ++;
  15. }
  16. M ++;
  17. }
CvSize tmpSize;tmpSize.width = width;tmpSize.height = height;IplImage *tmpImg = cvCreateImage(tmpSize, IPL_DEPTH_8U, 1);int m = startY;for(int i=0; i

Because the variable iplimage-> width is not the width after 4-byte alignment, the width in the svsize is not necessarily a multiple of 4 bytes when the image is created using cvcreateimage, the preceding Code uses width to cause image crossover. You can replace width with widthstep to solve the problem.

Images from the Internet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.