我在drawable文件夹中有一些图像文件.现在,我想将它们转换为opencv Mat对象.我发现了一个功能:
Mat img = Highgui.imread(inFile);
Run Code Online (Sandbox Code Playgroud)
正在读取文件路径以获取Mat.
但是,我无法获取图像的路径,因为我只能使用像R.drawable.img1这样的ID来读取它们.
我怎么能实现我想要的?
我遇到了问题cv::imshow.对于我的图像尺寸,它通常消耗大约1-2毫秒的处理时间,但在我的处理管道中的某个时刻,对于相同类型的图像,它使用4-8毫秒.
我有一个方法
void Tool::displayImage()
{
startTimeMeasure();
cv::imshow("output",image);
evaluateTimeMeasure();
}
Run Code Online (Sandbox Code Playgroud)
image是一个成员变量,highgui窗口是在其他地方创建的.时间测量与boost::posix_time ptime和time_duration.
cvStartWindowThread();
Run Code Online (Sandbox Code Playgroud)
被称为.
关键是,如果displayImage()在复杂的处理链中调用(从视频文件加载图像,某些预处理等),则cv::imshow变得非常慢,而在"暂停"视频中调用以重绘更新的图像的速度非常快.
如果我cv::waitKey(10)在时间测量开始之前添加一个cv::imshow,也变得快速.所以可能会有一些(gui?)需要处理哪些块cv::imshow?cv::waitKey(40)在循环中的单独线程中调用,等待键盘输入来控制(例如暂停/恢复)视频.据我所知,cv::imshow是在某种cv::waitKey时间段处理的队列中执行的?!?在哪里可以找到有关在此期间执行的所有任务的信息?也许我可以重新安排我的代码的某些部分(现在真的很复杂),以便一直保持更快imshow.
那么在一个cv::imshow调用中会发生什么,以及在不同情况下同一个调用缓慢/快速执行的原因是什么?
编辑:在"暂停"模式下我在常规执行和处理之间识别的一个区别是,在暂停模式下,该方法是从绑定的鼠标回调函数(来自windowThread?中)启动的,而在常规模式下,它是从主处理线程启动的.
我最近在我的 Ubuntu 18.04 LTS 上从 OpenCV3.3 迁移到了最新版本的 OpenCV4。我在安装过程中遇到了一些持续的问题。当我按照本安装教程进行安装时,我的安装没有出现任何错误。但是每当我opencv2/highgui.hpp在我的项目中包含该模块时,我都会遇到如下问题。当我点击此链接时,这似乎是由 highgui.hpp 引起的问题。
/home/arun/Documents/AutonomousLaneDetection/app/main.cpp: In function ‘int main(int, char**)’:
/home/arun/Documents/AutonomousLaneDetection/app/main.cpp:118:36: error: ‘CV_CAP_PROP_FRAME_WIDTH’ was not declared in this scope
int videoWidth = videofile.get(CV_CAP_PROP_FRAME_WIDTH);
^~~~~~~~~~~~~~~~~~~~~~~
/home/arun/Documents/AutonomousLaneDetection/app/main.cpp:119:37: error: ‘CV_CAP_PROP_FRAME_HEIGHT’ was not declared in this scope
int videoHeight = videofile.get(CV_CAP_PROP_FRAME_HEIGHT);
^~~~~~~~~~~~~~~~~~~~~~~~
/home/arun/Documents/AutonomousLaneDetection/app/main.cpp:123:27: error: ‘CV_FOURCC’ was not declared in this scope
CV_FOURCC('M', 'J', 'P', 'G'), 10,
^~~~~~~~~
/home/arun/Documents/AutonomousLaneDetection/app/main.cpp:123:27: note: suggested alternative: ‘CV_BLUR’
CV_FOURCC('M', 'J', 'P', 'G'), 10,
^~~~~~~~~
CV_BLUR
Run Code Online (Sandbox Code Playgroud) 我试过从drawable文件夹中读取图像.我正在使用eclipse ide.我运行下面的代码,但没有加载图像.代码取自这里
Mat image = new Mat(new Size(500,500 ),CvType.CV_8U);// Change CvType as you need.
image = Highgui.imread("icon.png");
if(image.empty()) {
Log.i(TAG, "Empty image!");
}
Run Code Online (Sandbox Code Playgroud)
我的drawable文件夹的屏幕截图如下:

如何加载此图像?
我已经构建了OpenCV框架IOS,我正在OpenCV从头学习,框架编译得很好,当我运行这段代码时:
IplImage *img = cvLoadImage("dpad_off.png");
cvNamedWindow("Example1",CV_WINDOW_NORMAL);
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Example1");
Run Code Online (Sandbox Code Playgroud)
应用程序崩溃与此日志:
OpenCV Error: Unspecified error (The function is not implemented.
Rebuild the library with Windows, GTK+ 2.x or Carbon support.
If you are on Ubuntu or Debian, install libgtk2.0-dev andpkg-config,
then re-run cmake or configure script) in cvNamedWindow, file /Volumes/minijHome/Documents/xcode_mini/hillegass/advancedIOS/postCourse/openCV/clean- downloads/openCVgitClone/opencv/modules/highgui/src/window.cpp, line 652
libc++abi.dylib: terminate called throwing an exception
Run Code Online (Sandbox Code Playgroud)
我试图在网上寻找答案,但无法弄清楚为什么会这样.任何的想法 ?