我使用的程序squares.c的OpenCV库的样本中找到.它适用于每个图像,但我真的无法弄清楚为什么它不能识别该图像中绘制的正方形
http://desmond.imageshack.us/Himg12/scaled.php?server=12&filename=26725680.jpg&res=medium
CANNY之后:http: //img847.imageshack.us/img847/6787/canny.jpg
在DILATE之后:http: //img593.imageshack.us/img593/3010/dilate.jpg
在RESULT图像(红色) http://img267.imageshack.us/img267/8016/resultuq.jpg
如您所见,未检测到方形.
在检测之后,我需要提取广场中包含的区域......没有投资回报率怎么可能?
在Opencv的python包装器中有任何方法/函数可以在二进制图像中找到黑色区域吗?(就像Matlab中的regionprops)到目前为止,我加载了我的源图像,通过阈值将其转换为二进制图像,然后将其反转以突出显示黑色区域(现在是白色).
我不能使用第三方库,如cvblobslob或cvblob
我有一个包含正方形的图像,我需要提取该正方形中包含的区域.在应用了square.c脚本(在每个OpenCV分布的样本中可用)后,我获得了一个正方形向量,然后我需要为它们中的每个保存一个图像.
用户karlphillip建议:
for (size_t x = 0; x < squares.size(); x++)
{
Rect roi(squares[x][0].x, squares[x][0].y,
squares[x][1].x - squares[x][0].x,
squares[x][3].y - squares[x][0].y);
Mat subimage(image, roi);
}
Run Code Online (Sandbox Code Playgroud)
为了在原始图像中检测到的所有方块生成一个称为子图像的新Mat
正如卡尔记得的那样,图像中检测到的点可能并不代表一个完美的正方形(如上图所示),但我刚给你建议的代码假设他们这样做了.
实际上我收到了这个错误:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width &&
roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height &&
roi.y + roi.height <= m.rows) in Mat, file /usr/include/opencv/cxmat.hpp,
line 187
terminate called after throwing an instance of 'cv::Exception'
what(): /usr/include/opencv/cxmat.hpp:187: error: …Run Code Online (Sandbox Code Playgroud) 我刚刚将我的系统从ubuntu 11.04更新到11.10,现在我再也无法编译任何包含对OpenCV库的引用的C程序
我已经尝试重新安装OpenCV(我使用2.1版本),但我遇到了这个错误:
/tmp/ccArHTZL.o: In function `main':
z.c:(.text+0x59): undefined reference to `cvLoadImage'
z.c:(.text+0xa0): undefined reference to `cvNamedWindow'
z.c:(.text+0xb1): undefined reference to `cvShowImage'
z.c:(.text+0xbb): undefined reference to `cvWaitKey'
z.c:(.text+0xc5): undefined reference to `cvDestroyWindow'
z.c:(.text+0xd1): undefined reference to `cvReleaseImage'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
为了安装OpenCV,我总是遵循这个过程:
$ sudo apt-get install libcv2.1 libcv-dev libcvaux2.1 libcvaux-dev libhighgui2.1
libhighgui-dev opencv-doc python-opencv
$ export LD_LIBRARY_PATH=/home/opencv/lib
$ export PKG_CONFIG_PATH=/home/opencv/lib/pkgconfig
$ pkg-config --cflags opencv
-I/usr/include/opencv
$ pkg-config --libs opencv
-lcxcore -lcv -lhighgui -lcvaux -lml
$ g++ …Run Code Online (Sandbox Code Playgroud) 我遇到了 OpenCv 的 python 包装器的问题。如果黑色像素的数量大于阈值,我有这个函数返回 1
def checkBlackPixels( img, threshold ):
width = img.width
height = img.height
nchannels = img.nChannels
step = img.widthStep
dimtot = width * height
data = img.imageData
black = 0
for i in range( 0, height ):
for j in range( 0, width ):
r = data[i*step + j*nchannels + 0]
g = data[i*step + j*nchannels + 1]
b = data[i*step + j*nchannels + 2]
if r == 0 and g == 0 and b == …Run Code Online (Sandbox Code Playgroud) 我需要在列表中插入一系列名称(如'Alam\xc3\xa9'),而不是将它们保存到SQLite数据库中.
我知道我可以通过tiping正确渲染这些名称:
print eval(repr(NAME)).decode("utf-8")
Run Code Online (Sandbox Code Playgroud)
但我必须将它们插入列表中,所以我不能使用打印
没有打印的其他方法吗?