Неверный идентификатор с NSRect frame = [self frame] - PullRequest
0 голосов
/ 18 января 2011

В настоящее время я пытаюсь выяснить, как изменить кадры с веб-камеры для игры с обнаружением движения.Я очень плохо знаком с Objective-C, и мне не удалось найти простой способ сделать это.

Мой вопрос здесь об ошибке, связанной с этим методом:

- (void)captureOutput:(QTCaptureOutput *)captureOutput 
  didOutputVideoFrame:(CVImageBufferRef)videoFrame
     withSampleBuffer:(QTSampleBuffer *)sampleBuffer 
       fromConnection:(QTCaptureConnection *)connection
{


    CIContext *myCIContext;
    const NSOpenGLPixelFormatAttribute attr[] = {
        NSOpenGLPFAAccelerated,
        NSOpenGLPFANoRecovery,
        NSOpenGLPFAColorSize, 32,
        0
    };
    NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:(void *)&attr];
    myCIContext = [CIContext contextWithCGLContext: CGLGetCurrentContext()
                                       pixelFormat: [pf CGLPixelFormatObj]
                                           options: nil];
    CVImageBufferRef releasedImageBuffer;
    CVBufferRetain(videoFrame);

    CIImage *picture = [CIImage imageWithCVImageBuffer:releasedImageBuffer];
    NSRect frame = [self frame];
    CGRect imageRect;
    imageRect = [picture extent];

    [colorCorrectionFilter setValue:picture forKey:@"inputImage"];
    [effectFilter setValue:[colorCorrectionFilter valueForKey:@"outputImage"] forKey:@"inputImage"];

    // render our resulting image into our context
    [ciContext drawImage:[compositeFilter valueForKey:@"outputImage"] 
                 atPoint:CGPointMake((int)((frame.size.width - imageRect.size.width) * 0.5), (int)((frame.size.height - imageRect.size.height) * 0.5)) // use integer coordinates to avoid interpolation
                fromRect:imageRect];

    @synchronized(self)
    {
        //basically, have frame to be released refer to the current frame
        //then update the reference to the current frame with the next frame in the "video stream"
        releasedImageBuffer = mCurrentImageBuffer;
        mCurrentImageBuffer = videoFrame;
    }

    CVBufferRelease(releasedImageBuffer);

}

Полученное сообщение об ошибке гласит:

warning: 'MyRecorderController' may not respond to '-frame'
error: invalid initializer

и выделенная строка:

NSRect frame = [self frame];

Мой заголовок в настоящее время выглядит так:

#import <QuickTime/ImageCompression.h>
#import <QuickTime/QuickTime.h>
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreVideo/CoreVideo.h>


@interface MyRecorderController : NSObject{ 
    IBOutlet QTCaptureView *mCaptureView;

    IBOutlet NSPopUpButton *videoDevicePopUp;
    NSMutableDictionary *namesToDevicesDictionary;
    NSString *defaultDeviceMenuTitle;

    CVImageBufferRef mCurrentImageBuffer;
    QTCaptureDecompressedVideoOutput *mCaptureDecompressedVideoOutput;

    // filters for CI rendering
    CIFilter            *colorCorrectionFilter; // hue saturation brightness control through one CI filter
    CIFilter            *effectFilter;          // zoom blur filter
    CIFilter            *compositeFilter;       // composites the timecode over the video
    CIContext           *ciContext;

    QTCaptureSession *mCaptureSession;
    QTCaptureMovieFileOutput *mCaptureMovieFileOutput;
    QTCaptureDeviceInput *mCaptureDeviceInput;

}

@end

Я смотрел научебник, и я не понимаю, что я сделал не так.Насколько я вижу (судя по приведенному примеру кода), мне не нужно включать протокол в это - что и предложили другие сайты.Я попробовал это, хотя, и в то время как это действительно компилирует, это заканчивает тем, что вывело:

2011-01-18 10:19:11.511 MyRecorder[9972:c903] -[MyRecorderController frame]: unrecognized selector sent to instance 0x1001525f0
2011-01-18 10:19:11.512 MyRecorder[9972:c903] *** Ignoring exception: -[MyRecorderController frame]: unrecognized selector sent to instance 0x1001525f0

Есть что-то, что я сделал неправильно, который вызвал это?Если нет, то есть ли лучший способ управлять кадрами с веб-камеры (и выводить их на экран)?

Спасибо, куча!

1 Ответ

2 голосов
/ 18 января 2011

Вы пытаетесь вызвать фрейм метода в MyRecorderController - у которого просто нет этого метода.Возможно, этот класс должен наследоваться от UIView, или вам нужно реализовать этот метод.

Спросите себя, что вы имеете в виду, и напишите соответствующий метод.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...