Search Results

Search found 2 results on 1 pages for 'prateeak ojha'.

Page 1/1 | 1 

  • Array sum of difference of first smallest k elment

    - by prateeak ojha
    Hi i come across this challenge on an online programing challange the task is so simple for ex WE have to variable N and K where N is where N is lenght of array and we have to find sum of duiffrence of K smallest element of array as Sample Input 10 4 1 2 3 4 10 20 30 40 100 200 Sample Output 10 Explanation #0 We have 10 as N size of array and K is 4 here the next N values are array's elments in order to find sum of diffrences we will takek smallest values from array which are 1,2,3,4 then will perform operation(sum of difference) as |1-2| + |1-3| + |1-4| + |2-3| + |2-4| + |3-4| = 10 I tried solving the problem and found a way through which i can solve the problem wit N^3 complexity but my solution is rejected i need a approach to solve the problem with n complexity i still can't figure out a way .. looked at some solution but coud'nt find the exact way to approach. if anybody have a better idea and would like to share it would be appreciable thanks in advance

    Read the article

  • Crop circular or elliptical image from original UIImage

    - by vikas ojha
    I am working on openCV for detecting the face .I want face to get cropped once its detected.Till now I got the face and have marked the rect/ellipse around it on iPhone. Please help me out in cropping the face in circular/elliptical pattern (UIImage *) opencvFaceDetect:(UIImage *)originalImage { cvSetErrMode(CV_ErrModeParent); IplImage *image = [self CreateIplImageFromUIImage:originalImage]; // Scaling down /* Creates IPL image (header and data) ----------------cvCreateImage CVAPI(IplImage*) cvCreateImage( CvSize size, int depth, int channels ); */ IplImage *small_image = cvCreateImage(cvSize(image->width/2,image->height/2), IPL_DEPTH_8U, 3); /*SMOOTHES DOWN THYE GUASSIAN SURFACE--------:cvPyrDown*/ cvPyrDown(image, small_image, CV_GAUSSIAN_5x5); int scale = 2; // Load XML NSString *path = [[NSBundle mainBundle] pathForResource:@"haarcascade_frontalface_default" ofType:@"xml"]; CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad([path cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL, NULL); // Check whether the cascade has loaded successfully. Else report and error and quit if( !cascade ) { NSLog(@"ERROR: Could not load classifier cascade\n"); //return; } //Allocate the Memory storage CvMemStorage* storage = cvCreateMemStorage(0); // Clear the memory storage which was used before cvClearMemStorage( storage ); CGColorSpaceRef colorSpace; CGContextRef contextRef; CGRect face_rect; // Find whether the cascade is loaded, to find the faces. If yes, then: if( cascade ) { CvSeq* faces = cvHaarDetectObjects(small_image, cascade, storage, 1.1f, 3, 0, cvSize(20, 20)); cvReleaseImage(&small_image); // Create canvas to show the results CGImageRef imageRef = originalImage.CGImage; colorSpace = CGColorSpaceCreateDeviceRGB(); contextRef = CGBitmapContextCreate(NULL, originalImage.size.width, originalImage.size.height, 8, originalImage.size.width * 4, colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault); //VIKAS CGContextDrawImage(contextRef, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), imageRef); CGContextSetLineWidth(contextRef, 4); CGContextSetRGBStrokeColor(contextRef, 1.0, 1.0, 1.0, 0.5); // Draw results on the iamge:Draw all components of face in the form of small rectangles // Loop the number of faces found. for(int i = 0; i < faces->total; i++) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // Calc the rect of faces // Create a new rectangle for drawing the face CvRect cvrect = *(CvRect*)cvGetSeqElem(faces, i); // CGRect face_rect = CGContextConvertRectToDeviceSpace(contextRef, // CGRectMake(cvrect.x * scale, cvrect.y * scale, cvrect.width * scale, cvrect.height * scale)); face_rect = CGContextConvertRectToDeviceSpace(contextRef, CGRectMake(cvrect.x*scale, cvrect.y , cvrect.width*scale , cvrect.height*scale*1.25 )); facedetectapp=(FaceDetectAppDelegate *)[[UIApplication sharedApplication]delegate]; facedetectapp.grabcropcoordrect=face_rect; NSLog(@" FACE off %f %f %f %f",facedetectapp.grabcropcoordrect.origin.x,facedetectapp.grabcropcoordrect.origin.y,facedetectapp.grabcropcoordrect.size.width,facedetectapp.grabcropcoordrect.size.height); CGContextStrokeRect(contextRef, face_rect); //CGContextFillEllipseInRect(contextRef,face_rect); CGContextStrokeEllipseInRect(contextRef,face_rect); [pool release]; } } CGImageRef imageRef = CGImageCreateWithImageInRect([originalImage CGImage],face_rect); UIImage *returnImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); CGContextRelease(contextRef); CGColorSpaceRelease(colorSpace); cvReleaseMemStorage(&storage); cvReleaseHaarClassifierCascade(&cascade); return returnImage; } } Thanks Vikas

    Read the article

1