私はカメラに接続するopenCvベースのdllを持っています。その後、cv::mat
オブジェクトをC#アプリケーションに呼び出し、画像をピクチャボックスオブジェクトのビットマップとして表示します。 これはうまくいきますが、画像が時折「不具合」になり、数秒ごとに点滅、静的およびポップが表示されます。dllからwindowsにopencv Matを呼び出すと、画像がぼやけて表示されます
ビットマップを表示する前にビットマップが有効かどうかを確認する方法はありますか? cv::imshow
を使用して、dllでイメージを表示すると、問題なく表示されます。
私が持っているコードは次のとおりです。
C++のdllで:C#の側で
__declspec(dllexport) uchar* getArucoFrame(void)
{
cv::Mat OriginalImg = returnLeftFrame(); // calls the frame from where the camera thread stores it.
cv::Mat tmp;
cv::cvtColor(OriginalImg, tmp, CV_BGRA2BGR);
//if I cv::imshow the Mat here, it looks good.
return tmp.data;
}
:
//on a button
threadImageShow = new Thread(imageShow);
threadImageShow.Start();
//show image frame in box
private void imageShow()
{
while(true)
{
IntPtr ptr = getArucoFrame();
if (pictureBoxFrame.Image != null)
{
pictureBoxFrame.Image.Dispose();
}
Bitmap a = new Bitmap(640, 360, 3 * 640, PixelFormat.Format24bppRgb, ptr);
pictureBoxFrame.Image = a;
Thread.Sleep(20);
}
}
// DLLの呼び出し
[DllImport("Vector.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr getArucoFrame();
イメージがdllでうまく見え、不思議な私としてnピクチャボックス、これをデバッグするのに問題があります。どんな助けでも大歓迎です。ありがとうございました。
ありがとうございました!私は数日間この上に私の髪を引き裂いています。非常にあなたの助けに感謝します。 – anti