Browse Source

Added CvInvoke.ImencodeAnimation and ImdecodeAnimation

master
Canming Huang 21 hours ago
parent
commit
7beb2c4718
  1. 25
      Emgu.CV.Extern/imgcodecs/imgcodecs_c_extra.cpp
  2. 8
      Emgu.CV.Extern/imgcodecs/imgcodecs_c_extra.h
  3. 105
      Emgu.CV/PInvoke/CvInvokeImgcodecs.cs

25
Emgu.CV.Extern/imgcodecs/imgcodecs_c_extra.cpp

@ -223,6 +223,16 @@ bool cveImreadAnimation(cv::String* filename, cv::Animation* animation, int star
throw_no_imgcodecs();
#endif
}
bool cveImdecodeAnimation(cv::_InputArray* buf, cv::Animation* animation, int start, int count)
{
#ifdef HAVE_OPENCV_IMGCODECS
return cv::imdecodeanimation(*buf, *animation, start, count);
#else
throw_no_imgcodecs();
#endif
}
bool cveImwriteAnimation(cv::String* filename, cv::Animation* animation, std::vector<int>* params)
{
#ifdef HAVE_OPENCV_IMGCODECS
@ -235,3 +245,18 @@ bool cveImwriteAnimation(cv::String* filename, cv::Animation* animation, std::ve
#endif
}
bool cveImencodeAnimation(
cv::String* ext,
cv::Animation* animation,
std::vector<uchar>* buf,
std::vector<int>* params)
{
#ifdef HAVE_OPENCV_IMGCODECS
if (params)
return cv::imencodeanimation(*ext, *animation, *buf, *params);
else
return cv::imencodeanimation(*ext, *animation, *buf);
#else
throw_no_imgcodecs();
#endif
}

8
Emgu.CV.Extern/imgcodecs/imgcodecs_c_extra.h

@ -73,9 +73,13 @@ CVAPI(std::vector<cv::Mat>*) cveAnimationGetFrames(cv::Animation* animation);
CVAPI(bool) cveImreadAnimation(cv::String* filename, cv::Animation* animation, int start, int count);
CVAPI(bool) cveImdecodeAnimation(cv::_InputArray* buf, cv::Animation* animation, int start, int count);
CVAPI(bool) cveImwriteAnimation(cv::String* filename, cv::Animation* animation, std::vector<int>* params);
CVAPI(bool) cveImencodeAnimation(
cv::String* ext,
cv::Animation* animation,
std::vector<uchar>* buf,
std::vector<int>* params);
#endif

105
Emgu.CV/PInvoke/CvInvokeImgcodecs.cs

@ -137,6 +137,8 @@ namespace Emgu.CV
/// </summary>
/// <param name="filename">The name of the file to be loaded</param>
/// <param name="readMode">The image reading mode</param>
/// <param name="metadataTypes">Output vector with types of metadata chucks returned in metadata</param>
/// <param name="metaData">Output vector of vectors or vector of matrices to store the retrieved metadata</param>
/// <returns>The loaded image</returns>
public static Mat ImreadWithMetadata(
String filename,
@ -160,7 +162,6 @@ namespace Emgu.CV
}
[DllImport(ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return: MarshalAs(CvInvoke.BoolMarshalType)]
private static extern void cveImreadWithMetadata(
IntPtr filename,
IntPtr metadataTypes,
@ -391,6 +392,45 @@ namespace Emgu.CV
[return: MarshalAs(CvInvoke.BoolMarshalType)]
private static extern bool cveImdecodemulti(IntPtr buf, int flags, IntPtr mats, ref Emgu.CV.Structure.Range range);
/// <summary>
/// Reads an image from a buffer in memory together with associated metadata.
/// The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the function returns an empty matrix.
/// </summary>
/// <param name="buf">Input array or vector of bytes.</param>
/// <param name="image">The output image</param>
/// <param name="readMode">The image reading mode</param>
/// <param name="metadataTypes">Output vector with types of metadata chucks returned in metadata</param>
/// <param name="metaData">Output vector of vectors or vector of matrices to store the retrieved metadata</param>
public static void ImdecodeWithMetadata(
IInputArray buf,
VectorOfInt metadataTypes,
IOutputArrayOfArrays metaData,
ImreadModes readMode,
Mat image
)
{
using (InputArray iaBuf = buf.GetInputArray())
using (OutputArray oaMetaData = metaData.GetOutputArray())
{
cveImdecodeWithMetadata(
iaBuf,
metadataTypes,
oaMetaData,
readMode,
image
);
}
}
[DllImport(ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
private static extern void cveImdecodeWithMetadata(
IntPtr buf,
IntPtr metadataTypes,
IntPtr metadata,
ImreadModes flags,
IntPtr dst);
/// <summary>
/// Encode image and return the result as a byte vector.
/// </summary>
@ -541,6 +581,36 @@ namespace Emgu.CV
[return: MarshalAs(CvInvoke.BoolMarshalType)]
private static extern bool cveImreadAnimation(IntPtr filename, IntPtr animation, int start, int count);
/// <summary>
///
/// </summary>
/// <param name="buf"></param>
/// <param name="animation"></param>
/// <param name="start"></param>
/// <param name="count"></param>
/// <returns></returns>
public static bool ImdecodeAnimation(
IInputArray buf,
Animation animation,
int start,
int count)
{
using (InputArray iaBuf = buf.GetInputArray())
{
return cveImdecodeAnimation(iaBuf, animation, start, count);
}
}
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return: MarshalAs(CvInvoke.BoolMarshalType)]
private static extern bool cveImdecodeAnimation(
IntPtr buf,
IntPtr animation,
int start,
int count);
/// <summary>
/// Saves an Animation to a specified file.
/// </summary>
@ -560,5 +630,38 @@ namespace Emgu.CV
[return: MarshalAs(CvInvoke.BoolMarshalType)]
private static extern bool cveImwriteAnimation(IntPtr filename, IntPtr animation, IntPtr parameters);
/// <summary>
/// Encodes an Animation to a memory buffer. The function imencodeanimation encodes the provided Animation data into a memory buffer in an animated format. Supported formats depend on the implementation and may include formats like GIF, AVIF, APNG, or WEBP.
/// </summary>
/// <param name="ext">The file extension that determines the format of the encoded data.</param>
/// <param name="animation">A constant reference to an Animation struct containing the frames and metadata to be encoded.</param>
/// <param name="buf">A reference to a vector of unsigned chars where the encoded data will be stored.</param>
/// <param name="parameters">Optional format-specific parameters</param>
/// <returns>Returns true if the animation was successfully encoded; returns false otherwise.</returns>
public static bool ImencodeAnimation(
String ext,
Animation animation,
VectorOfByte buf,
params KeyValuePair<CvEnum.ImwriteFlags, int>[] parameters)
{
using (CvString csExt = new CvString(ext))
using(VectorOfInt p = new VectorOfInt())
{
PushParameters(p, parameters);
return cveImencodeAnimation(
csExt,
animation,
buf,
p);
}
}
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
[return: MarshalAs(CvInvoke.BoolMarshalType)]
private static extern bool cveImencodeAnimation(
IntPtr ext,
IntPtr animation,
IntPtr buf,
IntPtr parameters);
}
}
Loading…
Cancel
Save