C\c++ level three pointer as formal parameter __c++

Source: Internet
Author: User

Second-level pointers and three-level pointers as specific applications of formal parameters:

When a second pointer is used as a parameter, the memory allocation is performed outside the function. Functions only need to be related operations, the three-level pointer as a formal parameter, you can allocate space within the function.

Level three pointers as parameter codes:

int skindetect (unsigned char *frame, int _width, int _height, rect*** ppp_rect, int *skin_size) {int width = _width;

	int height = _height;
	Cv::mat src;

	Cv::mat Skinmask;
	Src.create (Height * 3/2, width, cv_8uc1);

	Skinmask.create (height, width, cv_8uc1);

	Skinmask = 0;

	Cv::mat element = Cv::getstructuringelement (Cv::morph_rect, Cv::size (7, 7));

	
	memcpy (Src.data, frame, Height * Width * 3/2 * sizeof (unsigned char));


	Gaussianblur (SRC, src, cv::size (5, 5), 2, 2);
	unsigned char *pyplane = src.data;
	unsigned char *puplane = src.data + height * width;
	unsigned char *pvplane = src.data + (height * width)/4 * 5;



	unsigned char *pmask = skinmask.data;  for (int i = 0; i < HEIGHT/2 i++) for (int j = 0; J < Width/2; J +) {unsigned char u = puplane[i * WIDTH/2
		+ j];
		unsigned char v = pvplane[i * WIDTH/2 + j];

		unsigned char y = pyplane[2 * I * width + 2 * j]; if ((U > && u< 127) && (V > && v < 173)/*&& (y > && y <) * *//skin {pmask[2 * i * width + 2 * j] = 255;

			Pmask[2 * I * width + 2 * j + 1] = 255;
			pmask[(2 * i + 1) * Width + 2 * j] = 255;

		pmask[(2 * i + 1) * Width + 2 * j + 1] = 255;
	}/*imshow ("Skinmask", skinmask);

	Cv::waitkey (0); * * Morphologyex (Skinmask, Skinmask, cv::morph_dilate, Element);
	Look for outermost contour STD::VECTOR&LT;STD::VECTOR&LT;CV::P oint>> contours;
	Std::vector<cv::vec4i> hierarchy;

	Findcontours (Skinmask, contours, hierarchy, cv::retr_external, Cv::chain_approx_none, CV::P oint ()); Cv::mat imagecontours = Cv::mat::zeros (Skinmask.size (), CV_8UC1);

	Minimum external rectangular canvas **ppp_rect = (rect**) malloc (contours.size () * sizeof (rect*));//malloc 1 int cnt = 0;

		for (int i = 0; I<contours.size (); i++) {if (Contours[i].size () <) continue;

		Draw Contour Drawcontours (imagecontours, contours, I, cv::scalar (255), 1, 8, hierarchy); The smallest outer-junction rectangle cv::rotatedrect rect = minarearect for drawing the contour (contours[i]);
		CV::P oint2f p[4];

		Rect.points (P);
		int minx = MIN4 (p[0].x, p[1].x, p[2].x, p[3].x);

		int miny = MIN4 (P[0].y, P[1].y, P[2].y, P[3].Y);
		int maxx = max4 (p[0].x, p[1].x, p[2].x, p[3].x);

		int maxy = max4 (P[0].y, P[1].y, P[2].y, P[3].Y);
		Cv::rect Rect2 (Minx, Miny, Maxx-minx, Maxy-miny);

		_rect ret_rect{Minx, Miny, Maxx-minx, maxy-miny};

		cout << Minx << Endl; (*ppp_rect)

		[CNT] = (rect*) malloc (sizeof (Rect))//malloc 2 memset ((*ppp_rect) [CNT], 0, sizeof (Rect));

		memcpy ((*ppp_rect) [CNT], &ret_rect, sizeof (rect));
		Rectangle (imagecontours, Rect2, Cv::scalar::all (255), 2);

	cnt++;
	} *skin_size = cnt;
	Std::cout << endl<<cnt << Std::endl;
	Imshow ("Minarearect", imagecontours);

	Cv::waitkey (); /*if (Pp_rect = = NULL) std::cout << "error" << std::endl;*//*for (int i = 0; i < cnt; i++) {std::cout &L
	t;< "<< i <<" area: << (*pp_rect) [i]->_x << Std::endl;
}*/	return 0;
 }

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.