OpenCV从c++到C的转换
OpenCV conversion from C++ to C
我有一个c++ openCV代码,我需要转换为C。然而,我找不到一个指南来检查我应该使用什么而不是
cvScalar, cvNamedWindow, cvSmooth
另外,如果你在我的代码中看到任何其他问题,你能告诉我吗?
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include <stdio.h>
IplImage* Threshold(IplImage* src)
{
IplImage* srcHSV = cvCreateImage(cvGetSize(src), 8, 3);
cvCvtColor(src, srcHSV, CV_BGR2HSV);// Convert the BGR to HSV
IplImage* Thresholdimg = cvCreateImage(cvGetSize(src), 8, 1); // create a Threshold image
// HSV tresholding
cvInRangeS(srcHSV, CvScalar(7, 107, 219), CvScalar(11,148,255), Thresholdimg);
cvSmooth( Thresholdimg, Thresholdimg, CV_GAUSSIAN, 9, 9 ); // Smoothing with a Gaussian filter (9*9 kernel)
cvReleaseImage(&srcHSV);
return Thresholdimg;
}
int main()
{
CvCapture* capture = 0;
capture = cvCaptureFromCAM(1);// 1 for usb webcam, 0 o/w.
if(!capture)
{
printf("Can not capture,no device foundn");
return -1;
}
// Windows for Threshold and Output
cvNamedWindow("Tracking output");
cvNamedWindow("Threshold");
while(1) // infinite loop
{
IplImage* frame = 0;
frame = cvQueryFrame(capture); // decompress the captured frame
if(!frame)
break;
IplImage* finalthreshold = Threshold(frame);
cvShowImage("Threshold", finalthreshold);//show the thresholded image
CvMemStorage* storage = cvCreateMemStorage(0);// allocate memory to store the contour information
CvSeq* circles = cvHoughCircles(finalthreshold, storage, CV_HOUGH_GRADIENT, 2, finalthreshold->height/4, 100, 40, 20, 200);
int i;
for (i = 0; i < circles->total; i++)
{
float *p = (float*)cvGetSeqElem(circles, i);
printf("Ball! x=%f y=%f r=%fnr",p[0],p[1],p[2] );
CvPoint center = cvPoint(cvRound(p[0]),cvRound(p[1]));
CvScalar val = cvGet2D(finalthreshold, center.y, center.x);
if (val.val[0] < 1) continue;
cvCircle(frame, center, 3, CV_RGB(0,255,0), -1, CV_AA, 0);
cvCircle(frame, center, cvRound(p[2]), CV_RGB(255,0,0), 3, CV_AA, 0);
cvCircle(finalthreshold, center, 3, CV_RGB(0,255,0), -1, CV_AA, 0);
cvCircle(finalthreshold, center, cvRound(p[2]), CV_RGB(255,0,0), 3, CV_AA, 0);
}
cvShowImage("Tracking output", frame);
int c = cvWaitKey(27);
if(c!=-1)
break;
cvReleaseImage(&finalthreshold);
}
cvReleaseCapture(&capture);
return 0;
}
错误如下:
root@ghostrider:/home/zero/Desktop/deneme opencv# opencv untitled.c
compiling untitled.c
untitled.c: In function ‘Threshold’:
untitled.c:17:2: error: too few arguments to function ‘cvScalar’
In file included from /usr/local/include/opencv2/core/core_c.h:47:0,
from /usr/local/include/opencv/cv.h:63,
from untitled.c:1:
/usr/local/include/opencv2/core/types_c.h:1224:22: note: declared here
untitled.c:17:2: error: too few arguments to function ‘cvScalar’
In file included from /usr/local/include/opencv2/core/core_c.h:47:0,
from /usr/local/include/opencv/cv.h:63,
from untitled.c:1:
/usr/local/include/opencv2/core/types_c.h:1224:22: note: declared here
untitled.c:19:2: error: too few arguments to function ‘cvSmooth’
In file included from /usr/local/include/opencv/cv.h:65:0,
from untitled.c:1:
/usr/local/include/opencv2/imgproc/imgproc_c.h:81:13: note: declared here
untitled.c: In function ‘main’:
untitled.c:42:2: error: too few arguments to function ‘cvNamedWindow’
In file included from /usr/local/include/opencv/highgui.h:47:0,
from untitled.c:2:
/usr/local/include/opencv2/highgui/highgui_c.h:120:12: note: declared here
untitled.c:43:2: error: too few arguments to function ‘cvNamedWindow’
In file included from /usr/local/include/opencv/highgui.h:47:0,
from untitled.c:2:
/usr/local/include/opencv2/highgui/highgui_c.h:120:12: note: declared here
Output file => untitled
line 1224 at /usr/local/include/opencv2/core/types_c.h
CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
您提到的结构在C中以您给出的名称存在。您可以继续使用它们,使用C API而不是c++ API。
cvScalar
cvNamedWindow
cvSmooth
Edit:请注意,C实现没有默认参数。您需要为每个函数提供所有参数,即使您只是将默认参数粘贴到。
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 正在将指针转换为范围
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 是否可以从int转换为enum类类型
- 了解 GLM- openGL 中的相机转换
- 将无符号char*转换为std::istream*C++