社区
C++ 语言
帖子详情
IplImage* 转成 cv::Mat 类型后,depth变成了0
HLzhen
2016-07-19 04:30:31
cv::Mat dstMatGray(imgGray,true);
imgGray是IplImage*类型,它的depth为8,为什么使用Mat的拷贝构造函数之后,dstMatGray的depth就变成了0呢?求大神指点,这个问题已经困扰了我一天,不解决的话都没法往下敲了
...全文
154
3
打赏
收藏
IplImage* 转成 cv::Mat 类型后,depth变成了0
cv::Mat dstMatGray(imgGray,true); imgGray是IplImage*类型,它的depth为8,为什么使用Mat的拷贝构造函数之后,dstMatGray的depth就变成了0呢?求大神指点,这个问题已经困扰了我一天,不解决的话都没法往下敲了
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yshuise
2016-07-19
打赏
举报
回复
指针改成指针的引用了。
yshuise
2016-07-19
打赏
举报
回复
你的拷贝函数肯定没有改变这个值,不是什么大问题。
ID870177103
2016-07-19
打赏
举报
回复
Mat哪有这个构造函数?我用的opencv310
structure_grabber:使用OpenNI2(可选,Open
CV
和PCL)的结构传感器(深度和红外)的抓取器
#structure_grabber 使用 (可选, 和 )的(深度和红外)的抓取 ##要求 用法 准备 通过cmake创建项目 基本的 包括“ structure_grabber.h”。 首先,编写: StructureGrabber grabber; grabber.open(); 要捕获,请编写: grabber.acquire(); 要获取原始数据,请编写: unsigned short *
depth
_data, *infrared_data; grabber.copy
Depth
DataTo(
depth
_data); grabber.copyInfraredDataTo(infrared_data); 使用Open
CV
在包含“ structure_grabber.h”之前,请包含Open
CV
标头。 要获取
Ipl
Image
或
cv
::
Mat
,请编写:
cv
::M
java
cv
-platform-1.3.3-src
视频人脸识别,取代jmf。。。 Introduction Java
CV
uses wrappers from the JavaCPP Presets of commonly used libraries by researchers in the field of computer vision (Open
CV
, FFmpeg, libdc1394, PGR FlyCapture, OpenKinect, librealsense, CL PS3 Eye Driver, videoInput, ARToolKitPlus, and flandmark), and provides utility classes to make their functionality easier to use on the Java platform, including Android. Java
CV
also comes with hardware accelerated full-screen
image
display (CanvasFrame and GLCanvasFrame), easy-to-use methods to execute code in parallel on mult
ipl
e cores (Parallel), user-friendly geometric and color calibration of cameras and projectors (GeometricCalibrator, ProCamGeometricCalibrator, ProCamColorCalibrator), detection and
mat
ching of feature points (ObjectFinder), a set of classes that implement direct
image
alignment of projector-camera systems (mainly GN
Image
Aligner, ProjectiveTransformer, ProjectiveColorTransformer, ProCamTransformer, and ReflectanceInitializer), a blob analysis package (Blobs), as well as miscellaneous functionality in the Java
CV
class. Some of these classes also have an OpenCL and OpenGL counterpart, their names ending with CL or starting with GL, i.e.: Java
CV
CL, GLCanvasFrame, etc. To learn how to use the API, since documentation currently lacks, please refer to the Sample Usage section below as well as the sample programs, including two for Android (FacePreview.java and RecordActivity.java), also found in the samples directory. You may also find it useful to refer to the source code of ProCamCalib and ProCamTracker as well as examples ported from Open
CV
2 Cookbook and the associated wiki pages. Please keep me informed of any updates or fixes you make to the code so that I may integrate them into the next release. Thank you! And feel free to ask questions on the mailing list if you encounter any problems with the software! I am sure it is far from perfect... Downloads To install manually the JAR files, obtain the following archives and follow the instructions in the Manual Installation section below. Java
CV
1.3.3 binary archive java
cv
-platform-1.3.3-bin.zip (212 MB) Java
CV
1.3.3 source archive java
cv
-platform-1.3.3-src.zip (456 KB) The binary archive contains builds for Android, Linux, Mac OS X, and Windows. The JAR files for specific child modules or platforms can also be obtained individually from the Maven Central Repository. We can also have everything downloaded and installed auto
mat
ically with: Maven (inside the pom.xml file)
org.bytedeco
java
cv
-platform
1.3.3
Gradle (inside the build.gradle file) dependencies { compile group: 'org.bytedeco', name: 'java
cv
-platform', version: '1.3.3' } sbt (inside the build.sbt file) libraryDependencies += "org.bytedeco" % "java
cv
-platform" % "1.3.3" This downloads binaries for all platforms, but to get binaries for only one platform we can set the javacpp.platform system property (via the -D command line option) to something like android-arm, linux-x86_64, macosx-x86_64, windows-x86_64, etc. Please refer to the README.md file of the JavaCPP Presets for details. Another option available for Scala users is sbt-java
cv
. Required Software To use Java
CV
, you will first need to download and install the following software: An implementation of Java SE 7 or newer: OpenJDK http://openjdk.java.net/install/ or Sun JDK http://www.oracle.com/technetwork/java/javase/downloads/ or IBM JDK http://www.ibm.com/developerworks/java/jdk/ Further, although not always required, some functionality of Java
CV
also relies on: CL Eye Platform SDK (Windows only) http://codelaboratories.com/downloads/ Android SDK API 14 or newer http://developer.android.com/sdk/ JOCL and JOGL from JogAmp http://jogamp.org/ Finally, please make sure everything has the same bitness: 32-bit and 64-bit modules do not mix under any circumstances. Manual Installation Simply put all the desired JAR files (open
cv
*.jar, ffmpeg*.jar, etc.), in addition to javacpp.jar and java
cv
.jar, somewhere in your class path. Here are some more specific instructions for common cases: NetBeans (Java SE 7 or newer): In the Projects window, right-click the Libraries node of your project, and select "Add JAR/Folder...". Locate the JAR files, select them, and click OK. Eclipse (Java SE 7 or newer): Navigate to Project > Properties > Java Build Path > Libraries and click "Add External JARs...". Locate the JAR files, select them, and click OK. IntelliJ IDEA (Android 4.0 or newer): Follow the instructions on this page: http://developer.android.com/training/basics/firstapp/ Copy all the JAR files into the app/libs subdirectory. Navigate to File > Project Structure > app > Dependencies, click +, and select "2 File dependency". Select all the JAR files from the libs subdirectory. After that, the wrapper classes for Open
CV
and FFmpeg, for example, can auto
mat
ically access all of their C/C++ APIs: Open
CV
documentation FFmpeg documentation Sample Usage The class definitions are basically ports to Java of the original header files in C/C++, and I deliberately decided to keep as much of the original syntax as possible. For example, here is a method that tries to load an
image
file, smooth it, and save it back to disk: import static org.bytedeco.javacpp.open
cv
_core.*; import static org.bytedeco.javacpp.open
cv
_imgproc.*; import static org.bytedeco.javacpp.open
cv
_imgcodecs.*; public class Smoother { public static void smooth(String filename) {
Ipl
Image
image
=
cv
Load
Image
(filename); if (
image
!= null) {
cv
Smooth(
image
,
image
);
cv
Save
Image
(filename,
image
);
cv
Release
Image
(
image
); } } } Java
CV
also comes with helper classes and methods on top of Open
CV
and FFmpeg to facilitate their integration to the Java platform. Here is a small demo program demonstrating the most frequently useful parts: import java.io.File; import java.net.URL; import org.bytedeco.java
cv
.*; import org.bytedeco.javacpp.*; import org.bytedeco.javacpp.indexer.*; import static org.bytedeco.javacpp.open
cv
_core.*; import static org.bytedeco.javacpp.open
cv
_imgproc.*; import static org.bytedeco.javacpp.open
cv
_calib3d.*; import static org.bytedeco.javacpp.open
cv
_objdetect.*; public class Demo { public static void main(String[] args) throws Exception { String classifierName = null; if (args.length > 0) { classifierName = args[0]; } else { URL url = new URL("https://raw.github.com/Itseez/open
cv
/2.4.0/data/haarcascades/haarcascade_frontalface_alt.xml"); File file = Loader.extractResource(url, null, "classifier", ".xml"); file.deleteOnExit(); classifierName = file.getAbsolutePath(); } // Preload the open
cv
_objdetect module to work around a known bug. Loader.load(open
cv
_objdetect.class); // We can "cast" Pointer objects by instantiating a new object of the desired class.
Cv
HaarClassifierCascade classifier = new
Cv
HaarClassifierCascade(
cv
Load(classifierName)); if (classifier.isNull()) { System.err.println("Error loading classifier file \"" + classifierName + "\"."); System.exit(1); } // The available FrameGrabber classes include Open
CV
FrameGrabber (open
cv
_videoio), // DC1394FrameGrabber, FlyCaptureFrameGrabber, OpenKinectFrameGrabber, OpenKinect2FrameGrabber, // RealSenseFrameGrabber, PS3EyeFrameGrabber, VideoInputFrameGrabber, and FFmpegFrameGrabber. FrameGrabber grabber = FrameGrabber.createDefault(0); grabber.start(); // CanvasFrame, FrameGrabber, and FrameRecorder use Frame objects to communicate
image
data. // We need a FrameConverter to interface with other APIs (Android, Java 2D, or Open
CV
). Open
CV
FrameConverter.To
Ipl
Image
converter = new Open
CV
FrameConverter.To
Ipl
Image
(); // FAQ about
Ipl
Image
and
Mat
objects from Open
CV
: // - For custom raw processing of data, createBuffer() returns an NIO direct // buffer wrapped around the memory pointed by
image
Data, and under Android we can // also use that Buffer with Bitmap.copyPixelsFromBuffer() and copyPixelsToBuffer(). // - To get a Buffered
Image
from an
Ipl
Image
, or vice versa, we can chain calls to // Java2DFrameConverter and Open
CV
FrameConverter, one after the other. // - Java2DFrameConverter also has static copy() methods that we can use to transfer // data more directly between Buffered
Image
and
Ipl
Image
or
Mat
via Frame objects.
Ipl
Image
grabbed
Image
= converter.convert(grabber.grab()); int width = grabbed
Image
.width(); int height = grabbed
Image
.height();
Ipl
Image
gray
Image
=
Ipl
Image
.create(width, height,
IPL
_
DEPTH
_8U, 1);
Ipl
Image
rotated
Image
= grabbed
Image
.clone(); // Objects allocated with a create*() or clone() factory method are auto
mat
ically released // by the garbage collector, but may still be explicitly released by calling release(). // You shall NOT call
cv
Release
Image
(),
cv
ReleaseMemStorage(), etc. on objects allocated this way.
Cv
MemStorage storage =
Cv
MemStorage.create(); // The Open
CV
FrameRecorder class simply uses the
Cv
VideoWriter of open
cv
_videoio, // but FFmpegFrameRecorder also exists as a more versatile alternative. FrameRecorder recorder = FrameRecorder.createDefault("output.avi", width, height); recorder.start(); // CanvasFrame is a JFrame containing a Canvas component, which is hardware accelerated. // It can also switch into full-screen mode when called with a screenNumber. // We should also specify the relative monitor/camera response for proper gamma correction. CanvasFrame frame = new CanvasFrame("Some Title", CanvasFrame.getDefaultGamma()/grabber.getGamma()); // Let's create some random 3D rotation...
Cv
Mat
randomR =
Cv
Mat
.create(3, 3), randomAxis =
Cv
Mat
.create(3, 1); // We can easily and efficiently access the elements of
mat
rices and
image
s // through an Indexer object with the set of get() and put() methods. DoubleIndexer Ridx = randomR.createIndexer(), axisIdx = randomAxis.createIndexer(); axisIdx.put(0, (
Mat
h.random()-0.5)/4, (
Mat
h.random()-0.5)/4, (
Mat
h.random()-0.5)/4);
cv
Rodrigues2(randomAxis, randomR, null); double f = (width + height)/2.0; Ridx.put(0, 2, Ridx.get(0, 2)*f); Ridx.put(1, 2, Ridx.get(1, 2)*f); Ridx.put(2, 0, Ridx.get(2, 0)/f); Ridx.put(2, 1, Ridx.get(2, 1)/f); System.out.println(Ridx); // We can allocate native arrays using constructors taking an integer as argument.
Cv
Point hatPoints = new
Cv
Point(3); while (frame.isVisible() && (grabbed
Image
= converter.convert(grabber.grab())) != null) {
cv
ClearMemStorage(storage); // Let's try to detect some faces! but we need a grayscale
image
...
cv
Cv
tColor(grabbed
Image
, gray
Image
,
CV
_BGR2GRAY);
Cv
Seq faces =
cv
HaarDetectObjects(gray
Image
, classifier, storage, 1.1, 3,
CV
_HAAR_FIND_BIGGEST_OBJECT |
CV
_HAAR_DO_ROUGH_SEARCH); int total = faces.total(); for (int i = 0; i < total; i++) {
Cv
Rect r = new
Cv
Rect(
cv
GetSeqElem(faces, i)); int x = r.x(), y = r.y(), w = r.width(), h = r.height();
cv
Rectangle(grabbed
Image
,
cv
Point(x, y),
cv
Point(x+w, y+h),
Cv
Scalar.RED, 1,
CV
_AA, 0); // To access or pass as argument the elements of a native array, call position() before. hatPoints.position(0).x(x-w/10) .y(y-h/10); hatPoints.position(1).x(x+w*11/10).y(y-h/10); hatPoints.position(2).x(x+w/2) .y(y-h/2);
cv
FillConvexPoly(grabbed
Image
, hatPoints.position(0), 3,
Cv
Scalar.GREEN,
CV
_AA, 0); } // Let's find some contours! but first some thresholding...
cv
Threshold(gray
Image
, gray
Image
, 64, 255,
CV
_THRESH_BINARY); // To check if an output argument is null we may call either isNull() or equals(null).
Cv
Seq contour = new
Cv
Seq(null);
cv
FindContours(gray
Image
, storage, contour, Loader.sizeof(
Cv
Contour.class),
CV
_RETR_LIST,
CV
_CHAIN_APPROX_SIMPLE); while (contour != null && !contour.isNull()) { if (contour.elem_size() > 0) {
Cv
Seq points =
cv
ApproxPoly(contour, Loader.sizeof(
Cv
Contour.class), storage,
CV
_POLY_APPROX_DP,
cv
ContourPerimeter(contour)*0.02, 0);
cv
DrawContours(grabbed
Image
, points,
Cv
Scalar.BLUE,
Cv
Scalar.BLUE, -1, 1,
CV
_AA); } contour = contour.h_next(); }
cv
WarpPerspective(grabbed
Image
, rotated
Image
, randomR); Frame rotatedFrame = converter.convert(rotated
Image
); frame.show
Image
(rotatedFrame); recorder.record(rotatedFrame); } frame.dispose(); recorder.stop(); grabber.stop(); } } Furthermore, after creating a pom.xml file with the following content:
4.0.0
org.bytedeco.java
cv
demo
1.3.3
org.bytedeco
java
cv
-platform
1.3.3
And by placing the source code above in src/main/java/Demo.java, we can use the following command to have everything first installed auto
mat
ically and then executed by Maven: $ mvn compile exec:java -Dexec.mainClass=Demo Build Instructions If the binary files available above are not enough for your needs, you might need to rebuild them from the source code. To this end, the project files were created for: Maven 3.x http://maven.apache.org/download.html JavaCPP 1.3 https://github.com/bytedeco/javacpp JavaCPP Presets 1.3 https://github.com/bytedeco/javacpp-presets Once installed, simply call the usual mvn install command for JavaCPP, its Presets, and Java
CV
. By default, no other dependencies than a C++ compiler for JavaCPP are required. Please refer to the comments inside the pom.xml files for further details. Project lead: Samuel Audet [samuel.audet at gmail.com](mailto:samuel.audet at gmail.com) Developer site: https://github.com/bytedeco/java
cv
Discussion group: http://groups.google.com/group/java
cv
Ipl
Image
和
cv
::
Mat
间的转换
Ipl
Image
是Open
CV
中C语言的图像
类型
;
cv
::
Mat
是Open
CV
中C++语言的图像
类型
; 两者间相互转化实例如下:
cv
::
Mat
img_src =
cv
::imread(img_name);
cv
::
Mat
mimg = img_src.clone(); //
Ipl
Image
* img =
cv
Create
Image
Header(img_src.size(),
Cv
Arr,
Cv
Mat
,
Ipl
Image
,
cv
::
Mat
,
cv
::InputArray
一. Open
CV
中的
Cv
Arr,
Cv
Mat
,
Ipl
Image
,
cv
::
Mat
,
cv
::InputArray 1.1 看继承关系 typedef void
Cv
Arr; class
Mat
; struct
Cv
Mat
struct
Ipl
Image
; // Proxy datatype for passing
Mat
's and vector<>'s as input
Open
CV
Mat
、
Ipl
Image
及unsigned char* 相互转换(C++)
基于Open
CV
进行图像处理时,常常涉及
Mat
、
Ipl
Image
及unsigned char* 数据格式间的相互转换,本文进行了相互转换实现。
C++ 语言
64,648
社区成员
250,503
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章