当我尝试编译以下代码时,我得到一个链接器错误:Undefined symbols for architecture x86_64: "Foo()", referenced from: _main in main.o使用LLVM 4.2.
仅在标记函数时才会出现此问题constexpr.当标记功能时,程序会正确编译和链接const.为什么声明该函数constexpr会导致链接器错误?
(我意识到以这种方式编写函数不会带来编译时计算的好处;此时我很好奇为什么函数无法链接.)
main.cpp中
#include <iostream>
#include "test.hpp"
int main()
{
int bar = Foo();
std::cout << bar << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
test.hpp
constexpr int Foo();
Run Code Online (Sandbox Code Playgroud)
TEST.CPP
#include "test.hpp"
constexpr int Foo()
{
return 42;
}
Run Code Online (Sandbox Code Playgroud) 根据文档,这个函数应该返回一个Mat包含所有元素的元素.
Mat m = Mat::ones(2, 2, CV_8UC3);
Run Code Online (Sandbox Code Playgroud)
我期待得到一个2x2矩阵[1,1,1].相反,我得到了这个:
[1, 0, 0] [1, 0, 0]
[1, 0, 0] [1, 0, 0]
Run Code Online (Sandbox Code Playgroud)
这是预期的行为吗?
我想在一个大于某个阈值的区域的每个闭合轮廓周围绘制一个边界框,而不仅仅是最大的轮廓.我该怎么做呢?到目前为止,这是我尝试过的:
contours, _ = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
rect = cv2.boundingRect(c)
if rect[2] < 100 or rect[3] < 100: continue
print cv2.contourArea(c)
x,y,w,h = cv2.boundingRect(c)
cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),2)
cv2.putText(im,'Moth Detected',(x+w+10,y+h),0,0.3,(0,255,0))
cv2.imshow("Show",im)
cv2.waitKey()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud) 我正在使用g ++和opencv 2.4.6编写OpenCV项目
我有一些像这样的代码:
try
{
H = findHomography( obj, scene, CV_RANSAC );
}
catch (Exception &e)
{
if (showOutput)
cout<< "Error throwed when finding homography"<<endl;
errorCount++;
if (errorCount >=10)
{
errorCount = 0;
selected_temp = -99;
foundBB = false;
bb_x1 = 0;
bb_x2 = 0;
bb_y1 = 0;
bb_y2 = 0;
}
return -1;
}
Run Code Online (Sandbox Code Playgroud)
当findHomography无法找到时,将抛出错误.错误消息包括:
OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2)
== npoints && points1.type() == points2.type()) in findHomography,
file /Users/dji-mini/Downloads/opencv- 2.4.6/modules/calib3d/src/fundam.cpp,
line 1074
OpenCV …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个Mat与另一个相同的大小和类型.新的所有元素都Mat应该为零,所以我尝试了这个Mat::zeros(size, type)函数,定义如下:
static MatExpr zeros(Size size, int type);
Run Code Online (Sandbox Code Playgroud)
这是我的代码.假设我已经有了Mat g(创建过的imread):
Mat h = Mat::zeros(g.size, g.type());
Run Code Online (Sandbox Code Playgroud)
这会给我一个编译器错误,抱怨:
调用'零'没有匹配功能
我究竟做错了什么?
我正在做一个人脸识别项目。我的图片具有不同的照明,因此我需要进行照明归一化。我读了一篇声称进行照度归一化的论文。本文介绍了以下功能和值。
1-使用gamma = 0.2进行伽玛校正
2-(使用(sigma0 = 1,sigma1 = 2)进行高斯(DOG)滤波的差异)
3-对比度均衡(本文中使用截断阈值为10且压缩分量为0.1)
我CvPow用于伽玛校正,CvSmoothDoG和Threshold()截断(我不知道如何指定压缩分量),但是我没有得到确切的图像。我使用直方图均衡进行对比度均衡。
如果有人以前做过或有任何想法??
链接到本文:http : //lear.inrialpes.fr/pubs/2007/TT07/Tan-amfg07a.pdf
代码如下:(Peb Aryan的Python代码转换为JAVACV)
public static IplImage preprocessImg(IplImage img)
{
IplImage gf = cvCreateImage(cvSize(img.width(),img.height()),IPL_DEPTH_32F, 1 );
IplImage gr = IplImage.create(img.width(),img.height(), IPL_DEPTH_8U, 1);
IplImage tr = IplImage.create(img.width(),img.height(), IPL_DEPTH_8U, 1);
IplImage b1 = IplImage.create(img.width(),img.height(),IPL_DEPTH_32F, 1 );
IplImage b2 = IplImage.create(img.width(),img.height(),IPL_DEPTH_32F, 1 );
IplImage b3 = IplImage.create(img.width(),img.height(),IPL_DEPTH_32F, 1 );
CvArr mask = IplImage.create(0,0,IPL_DEPTH_8U, 1 );
cvCvtColor(img, gr, CV_BGR2GRAY);
gamma(gr,gr,gf);
cvSmooth(gf,b1,CV_GAUSSIAN, 1);
cvSmooth(gf,b2,CV_GAUSSIAN,23);
cvSub(b1,b2,b2,mask); …Run Code Online (Sandbox Code Playgroud) 我在 VS2010 中使用 OpenCV 2.4.6。
我认为我的网络摄像头无法捕捉画面。当我执行它成功构建的代码时,但我没有得到输出。我想,当我检查if(!bSuccess)它被执行并且无法从网络摄像头捕获帧时。
我该如何解决这个问题?我的代码如下:
#include "opencv2/highgui/highgui.hpp"
#include
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
if (!cap.isOpened()) // if not success, exit program
{
cout << "Cannot open the video file" << endl;
return -1;
}
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << …Run Code Online (Sandbox Code Playgroud) 我想在图像上使用引导过滤器来比较双边和引导过滤器,但我的引导过滤器代码显示错误:
AttributeError: 'module' object has no attribute 'GuidedFilter'
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?我的代码如下:
import cv2
import numpy as np
img = cv2.imread("C:\\Users\\Saloni\\Pictures\\p1.jpg")
guided = cv2.GuidedFilter(img,13,70)
cv2.imshow("image",img)
cv2.imshow("guided filtering",guided)
cv2.waitKey()
Run Code Online (Sandbox Code Playgroud) OpenCV中是否有与[srtd,srtdinds] = sort(dst,'ascend');Matlab 类似的函数?我试过cv::sortIdx(source, dst, cv::SORT_ASCENDING);但它不起作用.我的来源Mat包含一个列.
我正在尝试在android中使用自适应阈值处理(Bitmap),这需要将其更改为Mat然后将其转换为灰度.
下面是我的代码,从创建位图开始.它们被命名为crop,因为我刚刚在此之前裁剪了照片.
Bitmap bmCrop = BitmapFactory.decodeStream(iStream);
Bitmap bmThreshed = null;
/*
* Initialize the Mats
*/
Mat threshed = new Mat(bmCrop.getHeight(),bmCrop.getWidth(), CvType.CV_8UC1, new Scalar(4));//, new Scalar(4)
//Mat crop = new Mat();
Mat crop = new Mat(bmCrop.getHeight(),bmCrop.getWidth(), CvType.CV_8UC1,new Scalar(4));//, new Scalar(4)
/*
* Convert the Mats to Grayscale
*/
if(!threshed.empty())
Imgproc.cvtColor(threshed, threshed, Imgproc.COLOR_RGB2GRAY,1);// CURRENTLY BREAKING HERE
if(!crop.empty())
Imgproc.cvtColor(crop, crop, Imgproc.COLOR_BGR2GRAY,1);
Utils.bitmapToMat(bmCrop, crop);
// Mat src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C
Imgproc.adaptiveThreshold(crop, threshed, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, …Run Code Online (Sandbox Code Playgroud)