Opencv SLIC code
Opencv SLIC code
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <float.h>
using namespace std;
using namespace cv;
#include "slic.h"
int main(int argc, char *argv[]) {
/* Load the image and convert to Lab colour space. */
for(int i=1;i<=1863;i++)
{
stringstream ss;
ss<<i;
string si = "/home/me/Desktop/dataset/" + ss.str() + ".jpg";
Mat image;
image=imread(si,1);
IplImage *lab_image;
IplImage *image2;
lab_image=cvCreateImage(cvSize(image.cols,image.rows),8,3);
image2=cvCreateImage(cvSize(image.cols,image.rows),8,3);
IplImage ipltemp=image;
cvCopy(&ipltemp,lab_image);
cvCopy(&ipltemp,image2);
cvCvtColor(&image, lab_image, CV_BGR2Lab);
/* Yield the number of superpixels and weight-factors from the user. */
int w = image.cols, h = image.rows;
int nr_superpixels = atoi(argv[1]);
int nc = atoi(argv[2]);
double step = sqrt((w * h) / (double) nr_superpixels);
/* Perform the SLIC superpixel algorithm. */
Slic slic;
slic.generate_superpixels(lab_image, step, nc);
slic.create_connectivity(lab_image);
/* Display the contours and show the result. */
slic.display_contours(image2, CV_RGB(255,0,0));
Mat image3(image2);
imshow("result", image3);
cvWaitKey(0);
string ssave1 = "/home/me/Desktop/new_result/" + ss.str()+ ".jpg";
imwrite(ssave1,image3);
//cvSaveImage("/home/me/Desktop/img.jpg", image);
}
}
我收到此错误:在抛出"cv::异常"实例后终止调用 what():/tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20140819-1808/modules/core/src/matrix.cpp:698:错误:(-5) 函数 cvarrToMat 中的数组类型未知
在抛出"cv::异常"实例后终止调用 what():/tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20140819-1808/modules/core/src/matrix.cpp:698:错误:(-5) 函数 cvarrToMat 中的数组类型未知我是 cpp 编码的新手,有人可以说出问题所在吗?
- 使用OpenCV时,要警惕任何包含IplImages的内容。 必须过时且未维护
- 获取 https://github.com/berak/SLIC-Superpixels.git
- 更改您的代码:
--
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;
#include <opencv/opencv.hpp>
using namespace cv;
#include "slic.h"
int main(int argc, char *argv[]) {
/* Yield the number of superpixels and weight-factors from the user. */
int nr_superpixels = atoi(argv[1]);
int nc = atoi(argv[2]);
for(int i=1;i<=1863;i++)
{
/* Load the image and convert to Lab colour space. */
stringstream ss;
ss<<i;
string si = "/home/me/Desktop/dataset/" + ss.str() + ".jpg";
Mat image = imread(si,1);
Mat lab_image;
cvtColor(image, lab_image, COLOR_BGR2Lab);
double step = sqrt((image.total()) / (double) nr_superpixels);
/* Perform the SLIC superpixel algorithm. */
Slic slic;
slic.generate_superpixels(lab_image, step, nc);
slic.create_connectivity(lab_image);
/* Display the contours and show the result. */
slic.display_contours(image2, Vec3b(0,0,255));
imshow("result", image2);
waitKey(0);
string ssave1 = "/home/me/Desktop/new_result/" + ss.str()+ ".jpg";
imwrite(ssave1,image2);
}
}
相关文章:
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio Code "undefined reference to `WinMain@16'"
- VS Code "command":"make"与终端窗口中的命令行"make"不同
- 使用VS Code和CMake Tools运行自定义命令
- 修改 VS Code 中的默认C++代码段
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- std::to_string - 'to_string' 不是 'std' 的成员 - Visual Studio Code 1.42.0
- VS Code C++:不准确的系统包括路径错误(wchar.h,boost/lambda/lambda.hpp)
- C++新手,想知道如何使用VS code 2019播放音频文件
- "Unable to start debugging. No process is associated with this object." - 在Visual Studio Code中使用GDB
- 如何在Visual Studio Code中重命名我的a.exe文件?
- C++ Visual Studio Code 的设置不起作用
- 以某种方式告诉编译器"Do not process line of code"
- 在VS Code中编译C / C ++时如何禁用自动创建EXE文件?
- 将Qt与Visual Studio Code(Windows)一起使用
- 可视化 使用 VS Code 查找C++应用程序中的内存泄漏
- 将Visual Studio Code路径设置为.clang_format文件
- C++ Code 在 for 循环期间不会累积变量中的总和,仅提供最终迭代值
- Opencv SLIC code