New C++ API: Usage Example
{"Image DocumentName": "New C++ API: Usage Example", "Image ImageDescription": "Focus Detector. C: C++: double calcGradients(const IplImage  src, int aperture_size = 7) { CvSize sz = cvGetSize(src); IplImage  img16_x = cvCreateImage( sz, IPL_DEPTH_16S, 1); IplImage  img16_y = cvCreateImage( sz, IPL_DEPTH_16S, 1); cvSobel( src, img16_x, 1, 0, aperture_size); cvSobel( src, img16_y, 0, 1, aperture_size); IplImage  imgF_x = cvCreateImage( sz, IPL_DEPTH_32F, 1); IplImage  imgF_y = cvCreateImage( sz, IPL_DEPTH_32F, 1); cvScale(img16_x, imgF_x); cvScale(img16_y, imgF_y); IplImage  magnitude = cvCreateImage( sz, IPL_DEPTH_32F, 1); cvCartToPolar(imgF_x, imgF_y, magnitude); double res = cvSum(magnitude).val[0]; cvReleaseImage( &magnitude ); cvReleaseImage(&imgF_x); cvReleaseImage(&imgF_y); cvReleaseImage(&img16_x); cvReleaseImage(&img16_y); return res; } double contrast_measure(const Mat& img) { Mat dx, dy; Sobel(img, dx, 1, 0, 3, CV_32F); Sobel(img, dy, 0, 1, 3, CV_32F); magnitude(dx, dy, dx); return sum(dx)[0]; }", "Image XResolution": "37", "Image YResolution": "37", "Image ResolutionUnit": "Pixels/Centimeter", "Image Software": "SlidePlayer", "Image YCbCrPositioning": "Centered"}