The difference between the structure of OPENCV storage image and the structure of PictureBox storage image

Source: Internet
Author: User

During this time, I was doing a pedestrian statistics project based on EMGU, and when I framed the area, I found that there were always problems. Then I wrote a small program test, found the problem in the image matrix scan this piece

The coordinates of the mouse on the PictureBox are

And the EMGU is scanned from the Y direction.

1  for(intx =0; x < grayimage1.width; X + +)2                 {3                      for(inty =0; Y < Grayimage1.height; y++)4                     {5                         if(Imganalysis.isinarea (x, Y, plist))6                         {7                            grayimgdata[y, x, 0] = 0;8                         }9                     }Ten}

1. Capture the frame first with the capture class Emgu

1 New Capture (fileName); 2 frame = capture. Queryframe (); // one frame frame playback

2. Whether the scanning (x, y) point is within the framed area, the gray value of the point within the framed area is set to 0

1Image<gray,byte> GrayImage1 = frame. Convert<gray,byte>();2Byte[,,] Grayimgdata =Grayimage1.data;3              4                  for(intx =0; x < grayimage1.width; X + +)5                 {6                      for(inty =0; Y < Grayimage1.height; y++)7                     {8                         if(Isinarea (x, Y, plist))9                         {Ten                           grayimgdata[y, x, 0] = 0;//Gray value 0 One                         } A                     } -                 } -  thepictureBox1.Image = Grayimage1.bitmap;//effect on the PictureBox -  - //method: A decision algorithm specifically for whether a point exists within a polygon - parameter x, y is the spatial coordinate of the pixel point, plist is the list of points that store the polygon +          Public BOOLIsinarea (floatXfloatY, list<pointf>plist) -         { +             intNcount =plist. Count; A             intNcross =0; at              for(inti =0; I < plist. Count; i++) -             { -PointF P1 =NewPointF (ScaleHeight * plist[i]. X, ScaleWidth *Plist[i]. Y); -PointF P2 =NewPointF (ScaleHeight * plist[(i +1)% ncount]. X, ScaleWidth * plist[(i +1) %Ncount]. Y); -                 if(P1. Y = = P2. Y//p1p2 parallel to Y=p0.y -                     Continue; in  -                 if(Y < Math.min (P1. Y, p2. Y))//the intersection is on the p1p2 extension cord. to                     Continue; +  -                 if(Y >= Math.max (p1. Y, p2. Y))//the intersection is on the p1p2 extension cord. the                     Continue; *  $                 //to find the X-coordinate of the intersection--------------------------------------------------------------Panax Notoginseng  -                 DoubleXcross = (Double) (Y-P1. Y) * (Double) (P2. X-p1. X)/(Double) (P2. Y-p1. Y) +P1. X; the  +                 if(Xcross >x) Ancross++;//only single-sided intersections are counted the             } +  -             //The single -sided intersection is even, points outside the polygon--- $  $             return(Ncross%2==1); -}

3 Demo effect: Correct:

Error:

The difference between the structure of OPENCV storage image and the structure of PictureBox storage image

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.