我在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);
}
}
答案 0 :(得分:4)
答案 1 :(得分:1)
请查看以下网站以回答您的问题
http://opencv.willowgarage.com/wiki/OpenCV_GPU http://opencv.itseez.com/doc/tutorials/tutorials.html http://blog.cuvilib.com/2011/03/22/how-to-build-opencv-2-2-with-gpu-cuda-on-windows-7/