タイプ「_」の引数リストで「_」を呼び出すことはできません-2つの選択肢のどちらを使用する必要がありますか?

エドワード

このエラーが発生しました。私には2つの選択肢があると思います。私のコードに最適なのはどれですか?違いはどういう意味ですか?

タイプ '(Float、Float、Float)'の引数リストで 'RGBtoHSV'を呼び出すことはできません

RGBtoHSV(CGFloat(r), CGFloat(g), CGFloat(b))

RGBtoHSV(CGFloat(), CGFloat(), CGFloat())

また、スクリーンショットを見て、他のいくつかのエラーに関するいくつかの指針を教えていただければ、それも素晴らしいことです。タイプを一致させる必要があることはわかっていますが、構文の順序がわかりません。http://i.imgur.com/sAckG6h.png

ありがとう

func RGBtoHSV(r : CGFloat, g : CGFloat, b : CGFloat) -> (h : CGFloat, s : CGFloat, v : CGFloat) {
        var h : CGFloat = 0.0
        var s : CGFloat = 0.0
        var v : CGFloat = 0.0
        let col = UIColor(red: r, green: g, blue: b, alpha: 1.0)
        col.getHue(&h, saturation: &s, brightness: &v, alpha: nil)
        return (h, s, v)
    }



// process the frame of video
    func captureOutput(captureOutput:AVCaptureOutput, didOutputSampleBuffer sampleBuffer:CMSampleBuffer, fromConnection connection:AVCaptureConnection) {
        // if we're paused don't do anything
        if currentState == CurrentState.statePaused {
            // reset our frame counter
            self.validFrameCounter = 0
            return
        }

    // this is the image buffer
    var cvimgRef:CVImageBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)
    // Lock the image buffer
    CVPixelBufferLockBaseAddress(cvimgRef, 0)
    // access the data
    var width: size_t = CVPixelBufferGetWidth(cvimgRef)
    var height:size_t = CVPixelBufferGetHeight(cvimgRef)
    // get the raw image bytes
    let buf = UnsafeMutablePointer<UInt8>(CVPixelBufferGetBaseAddress(cvimgRef))
    var bprow: size_t = CVPixelBufferGetBytesPerRow(cvimgRef)


        var r:Float = 0.0
        var g:Float = 0.0
        var b:Float = 0.0

        for var y = 0; y < height; y++ {
            for var x:UInt8 = 0; x < width * 4; x += 4 {  // error: '<' cannot be applied to operands of type 'UInt8' and 'Int'
                b += buf[x]
                g += buf[x + 1]
                r += buf[x + 2]
            }
            buf += bprow(UnsafeMutablePointer(UInt8))  // error: '+=' cannot be applied to operands of type 'UnsafeMutablePointer<UInt8>' and 'size_t'
        }
        r /= 255 * (width*height)
        g /= 255 * (width*height)
        b /= 255 * (width*height)


    //} 



    // convert from rgb to hsv colourspace
        var h:Float = 0.0
        var s:Float = 0.0
        var v:Float = 0.0

    RGBtoHSV(r, g, b)  // error
kishikawa katsumi

型の不一致エラーがたくさんあります。

のタイプは、幅の値まで増加するためであっxはなりませんUInt8x

for var x:UInt8 = 0; x < width * 4; x += 4 {  // error: '<' cannot be applied to operands of type 'UInt8' and 'Int'

したがって、以下のように修正します。

for var x = 0; x < width * 4; x += 4 {

ポインタアドレスをインクリメントするには、advancedBy()関数を使用できます

buf += bprow(UnsafeMutablePointer(UInt8))  // error: '+=' cannot be applied to operands of type 'UnsafeMutablePointer<UInt8>' and 'size_t'

以下のように:

var pixel = buf.advancedBy(y * bprow)

そしてこの行、

RGBtoHSV(r, g, b)  // error

スウィフトには暗黙のキャストの間ではありませんCGFloatし、Float残念ながらは。したがって、明示的ににキャストする必要がありますCGFloat

RGBtoHSV(CGFloat(r), g: CGFloat(g), b: CGFloat(b))

編集されたコード全体はここにあります:

func RGBtoHSV(r: CGFloat, g: CGFloat, b: CGFloat) -> (h: CGFloat, s: CGFloat, v: CGFloat) {
    var h: CGFloat = 0.0
    var s: CGFloat = 0.0
    var v: CGFloat = 0.0
    let col = UIColor(red: r, green: g, blue: b, alpha: 1.0)
    col.getHue(&h, saturation: &s, brightness: &v, alpha: nil)
    return (h, s, v)
}

// process the frame of video
func captureOutput(captureOutput:AVCaptureOutput, didOutputSampleBuffer sampleBuffer:CMSampleBuffer, fromConnection connection:AVCaptureConnection) {
    // if we're paused don't do anything
    if currentState == CurrentState.statePaused {
        // reset our frame counter
        self.validFrameCounter = 0
        return
    }

    // this is the image buffer
    var cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer)
    // Lock the image buffer
    CVPixelBufferLockBaseAddress(cvimgRef, 0)
    // access the data
    var width = CVPixelBufferGetWidth(cvimgRef)
    var height = CVPixelBufferGetHeight(cvimgRef)
    // get the raw image bytes
    let buf = UnsafeMutablePointer<UInt8>(CVPixelBufferGetBaseAddress(cvimgRef))
    var bprow = CVPixelBufferGetBytesPerRow(cvimgRef)

    var r: Float = 0.0
    var g: Float = 0.0
    var b: Float = 0.0

    for var y = 0; y < height; y++ {
        var pixel = buf.advancedBy(y * bprow)
        for var x = 0; x < width * 4; x += 4 {  // error: '<' cannot be applied to operands of type 'UInt8' and 'Int'
            b += Float(pixel[x])
            g += Float(pixel[x + 1])
            r += Float(pixel[x + 2])
        }
    }
    r /= 255 * Float(width * height)
    g /= 255 * Float(width * height)
    b /= 255 * Float(width * height)

    //}

    // convert from rgb to hsv colourspace
    var h: Float = 0.0
    var s: Float = 0.0
    var v: Float = 0.0

    RGBtoHSV(CGFloat(r), g: CGFloat(g), b: CGFloat(b))  // error
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ