Open laszloban opened 1 year ago
After playing a bit more, I've found a workaround for the issue. It is working nicely both on intel and nvidia gpu's however it needs and extra, theoretically unnecessary copy of the image. This way I copy the source frame's UMat to a temp UMat, so I can dispose the source frame's UMat. Now I think the issue is maybe with the videocapture somehow.
UMat temp = new();
UMat translated= new UMat();
using (Mat srcFrame = new Mat())
{
Mat frame;
while (videocapture.Read(srcFrame))
{
Console.WriteLine($"Processing {idx} from {videocapture.FrameCount}...");
Cv2.ImShow("Result", srcFrame);
using (UMat uImg = srcFrame.GetUMat(AccessFlag.READ, UMatUsageFlags.DeviceMemory))
uImg.CopyTo(temp);
Cv2.WarpAffine(temp, translated, appliedTranslation, temp.Size());
frame = translated.GetMat(AccessFlag.RW);
videoWriter.Write(frame);
Cv2.ImShow("Result", frame);
Cv2.WaitKey(1);
frame.Dispose();
++idx;
}
videocapture.Release();
videoWriter.Release();
}
Summary of your issue
Trying to apply WarpAffine transform - using UMats - to each frame of a video file and write it back to a new file. I see very strange behaviour using an NVidia RTX 3060, as a lot of frames are become the same as the previous one. Displaying the source frame with ImShow shows even the source frames are corrupted.
Environment
Laptop - Corei7 with Iris-XE, Windows 11 22H2 Desktop - Ryzen 5 (no gpu) with RTX3060, Windows 11 22H2
What did you do when you faced the problem?
My code works perfectly on my laptop with an Intel CPU's built-in Iris-XE gpu. When I move to an other machine with an NVidia 3060, I can successfully run the code, but a lot of frames are become the same as the previous one. Displaying the source frame with ImShow shows even the source frames are corrupted.
I've tried to investigate a bit, if I does not dispose the original UMat - by removing the using statement - I can get perfect result on both machines, however its leaking gpu memory.
I've tried to replace the WarpAffine with a simple copy for test purposes, and it was working perfectly on both machines.
Example code:
Output:
What did you intend to be?