我是 GPU 编程的新手,在使用 GPU 之前我没有经验,我有一些功能,我必须转换这些功能以便它们在 GPU 中运行,cpu 版本运行良好,我使用 emgucv 进行图像操作. 我的代码在下面给出,请帮助我。
public static Image Highlight(Image image)
{
if (image == null)
{
throw new ArgumentNullException("image");
}
using (Image<Bgr, byte> originalImage = ConvertToEmgu(image))
using (Image<Bgr, byte> resavedOriginalImage = ConvertToEmgu(ResaveImageWithGivenCompression(image)))
using (Image<Bgr, byte> errorLevelImage = (originalImage - resavedOriginalImage) * scalingFactor)
{
return errorLevelImage.ToBitmap();
}
}
private static Image<Bgr, byte> ConvertToEmgu(Image image)
{
using (Bitmap bitmap = new Bitmap(image))
{
return new Image<Bgr, byte>(bitmap);
}
}
private static Image ResaveImage(Image image)
{
EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
ImageCodecInfo jpegWithGivenCompressionFormat = GetEncoderInfo("image/jpeg");
jpegEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, compressionQuality);
using (MemoryStream resavedImageStream = new MemoryStream())
{
image.Save(resavedImageStream, jpegWithGivenCompressionFormat, jpegEncoderParameters);
return Image.FromStream(resavedImageStream);
}
}
private static ImageCodecInfo GetEncoderInfo(string mimeType)
{
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
return encoders.FirstOrDefault(encoder => encoder.MimeType == mimeType);
}
}