BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.87k stars 609 forks source link

why can't filter second time? #272

Open claudebaek opened 6 years ago

claudebaek commented 6 years ago

Hi. I'm using gpuimage2 but there is difficult problem. i was tried to solve the problem over 3month but i can't possibly understand it.

following is my code in CameraViewController i captured photo and pass the image to ImageFilterViewController.

` let pictureOutput = PictureOutput() (self.filterOperation?.filter)! --> pictureOutput

        guard let destVC = self.storyboard?.instantiateViewController(withIdentifier: "ImageFilterViewController") as? ImageFilterViewController else { return }

        pictureOutput.imageAvailableCallback = { image in

            destVC.stillImage = image    
            destVC.pictureOutput = pictureOutput

            DispatchQueue.main.async {
                self.navigationController?.pushViewController(destVC, animated: true)
            }
        }
    }

`

following is ImageFilterViewController code

` override func viewDidLoad() { super.viewDidLoad() ... let filterImage = stillImage.filterWithOperation(filter)

}

`

at first time, there is no problem. I can get filtered image but if I back to CameraViewController and capture again, there is no filtered image. I checked stillImage and filter are not NIL.

I traced the code and checked that imageAvailableCallback was not callback at second time.

` public func filterWithPipeline(_ pipeline:(PictureInput, PictureOutput) -> ()) -> UIImage? { let picture = PictureInput(image:self) var outputImage:UIImage? let pictureOutput = PictureOutput() pictureOutput.onlyCaptureNextFrame = false

    pictureOutput.imageAvailableCallback = {image in
        outputImage = image
    }

    pipeline(picture, pictureOutput)

    picture.processImage(synchronously:true)

    return outputImage
}`

I added following codes that execute after capturing but it was no use.

       videoCamera.removeAllTargets()
            blendImage?.removeAllTargets()
            filterOperation = nil
            blendImage = nil

why there is no callback after first time? please help me. I did everything I can but it's impossible. thank you.