我正在尝试使用OpenCV 的C++ API将1296x968图像旋转90度,我遇到了一些问题.
输入:

旋转:

如您所见,旋转的图像存在一些问题.首先,它具有与原始尺寸相同的尺寸,即使我专门Mat使用原始尺寸的反转尺寸创建目的地.结果,目标图像被裁剪.
我怀疑这种情况正在发生,因为我正在调用warpAffine()并传递原始Mat大小而不是目标大小Mat.但我这样做是因为我遵循了这个答案,但现在我怀疑答案可能是错的.所以这是我的第一个怀疑/问题.
第二,是,warpAffine()是在一定的书面形式向目的地偏移(可能在旋转的数据复制到图像中)和该操作留下了可怕的大黑边的图像周围.
我该如何解决这些问题?
我正在分享以下源代码:
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
void rotate(Mat& image, double angle)
{
Point2f src_center(image.cols/2.0F, image.rows/2.0F);
Mat rot_matrix = getRotationMatrix2D(src_center, angle, 1.0);
Mat rotated_img(Size(image.size().height, image.size().width), image.type());
warpAffine(image, rotated_img, rot_matrix, image.size());
imwrite("rotated.jpg", rotated_img);
}
int main(int argc, char* argv[])
{ …Run Code Online (Sandbox Code Playgroud) CUDA 内核代码中断言的等效技术是什么?
似乎没有CUDA内核代码的断言.我想要一种在内核代码中轻松捕捉程序员错误的方法.一种机制,我可以设置需要为true的条件,并且当条件为false并且出现错误消息时内核应该挽救.
我正在尝试仅使用glTexCoord2f()和glVertex2f()实现OpenGL中的图像缩放.
让我解释一下:在加载a QImage并将其发送到gpu后,glTexImage2D()我必须根据Qt的规范执行图像缩放操作.Qt定义了这3个操作(见下图):

我认为这是唯一的方法,因为我的应用程序是一个Qt插件,这个任务需要paint()在类的方法内完成.这项IgnoreAspectRatio操作非常简单,现在正在运作.在KeepAspectRatio最初给了我一些麻烦,但现在它也在努力.不幸的是,KeepAspectRatioByExpanding让我很头疼.
我正在分享到目前为止我所做的事情,感谢您对此问题的帮助:
main.cpp中:
#include "oglWindow.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
oglWindow w;
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
oglWindow.cpp:
#include "oglWindow.h"
#include "glwidget.h"
#include <QGridLayout>
oglWindow::oglWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
GLWidget *openGL = new GLWidget(this);
QGridLayout *layout = new QGridLayout;
setLayout(layout);
}
oglWindow::~oglWindow()
{
}
Run Code Online (Sandbox Code Playgroud)
oglWindow.h:
#ifndef oglWindow_H …Run Code Online (Sandbox Code Playgroud) 关于CUDA内核如何工作,我有一个新手怀疑.
如果有以下代码(使用cuPrintf从这里获取的函数):
#include "cuPrintf.cu"
__global__ void testKernel(int param){
cuPrintf("Param value: %d\n", param);
}
int main(void){
// initialize cuPrintf
cudaPrintfInit();
int a = 456;
testKernel<<<4,1>>>(a);
// display the device's greeting
cudaPrintfDisplay();
// clean up after cuPrintf
cudaPrintfEnd();
}
Run Code Online (Sandbox Code Playgroud)
执行的输出是:
Param value: 456
Param value: 456
Param value: 456
Param value: 456
Run Code Online (Sandbox Code Playgroud)
我无法得到内核如何读取我传递的参数的正确值,是不是它在主机内存中分配?GPU可以从主机内存中读取吗?
谢谢,
安德里亚
我有一个带有printDebug方法的类.它没有在代码中的任何地方使用,但我想在使用gdb(使用调用)进行调试时使用它.这基本上是以一种格式良好的方式打印对象的内容,例如我可能有一组集合.用于此的g ++选项是什么?我试过-O0但这不起作用.
我使用的工作是在构造函数中对debugPrint进行伪调用,并提供一个bool来指示你是否真的要打印或什么都不做.这很好,但必须有一个更好的方法来做到这一点.
如果我理解正确--O0不应该做任何优化,所以不应该删除死代码,但也许我错了.
如何设置相机FPS?
可能是cvSetCaptureProperty(cameraCapture,CV_CAP_PROP_FPS,30); ?
但它返回HIGHGUI ERROR:V4L2:无法获取属性(5) - 参数无效
因为highgui/cap_v4l.cpp中没有实现
static int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture,
int property_id, double value ){
static int width = 0, height = 0;
int retval;
/* initialization */
retval = 0;
/* two subsequent calls setting WIDTH and HEIGHT will change
the video size */
/* the first one will return an error, though. */
switch (property_id) {
case CV_CAP_PROP_FRAME_WIDTH:
width = cvRound(value);
if(width !=0 && height != 0) {
retval = icvSetVideoSize( capture, width, height);
width …Run Code Online (Sandbox Code Playgroud) 到目前为止,我的项目只有.cpp 文件被编译成不同的二进制文件,我设法配置CPack来构建一个正确的debian包,没有任何问题.
最近我写了几个python应用程序并将它们添加到项目中,以及一些我想要合并到包中的自定义模块.
编写setup.py脚本之后,我想知道如何将这些文件添加到CPack配置中,setup.py以便在用户在系统上安装软件包时自动执行dpkg -i package.deb.
我很难找到有关如何配置CPack以安装自定义python应用程序/模块的相关信息.有没人试过这个?
我的目标是识别图像中存在的所有形状.这个想法是:
示例图片:

我用它fitEllipse()来找到轮廓最合适的椭圆,但结果有点乱:

可能正确的椭圆用蓝色填充,边界椭圆用黄色填充.可能不正确的轮廓用绿色填充,(错误的)边界椭圆是青色.
正如您所看到的,在第一行中限定三角形的椭圆看起来非常适合最佳拟合.第三行中三角形的边界椭圆似乎不是最合适的,但仍然可以作为拒绝不正确椭圆的标准.
但我无法理解为什么剩下的三角形在其轮廓之外完全具有边界椭圆.最坏的情况是最后一行中的第三个三角形:椭圆是完全错误的,但碰巧有一个区域靠近轮廓的区域,因此三角形被错误地识别为椭圆.
我想念什么吗?我的代码:
#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;
using namespace cv;
void getEllipses(vector<vector<Point> >& contours, vector<RotatedRect>& ellipses) {
ellipses.clear();
Mat img(Size(800,500), CV_8UC3);
for (unsigned i = 0; i<contours.size(); i++) {
if (contours[i].size() >= 5) {
RotatedRect temp = fitEllipse(Mat(contours[i]));
if (area(temp) <= 1.1 * contourArea(contours[i])) {
//cout << area(temp) << " < 1.1* " << contourArea(contours[i]) << endl;
ellipses.push_back(temp);
drawContours(img, contours, i, Scalar(255,0,0), -1, 8);
ellipse(img, temp, …Run Code Online (Sandbox Code Playgroud) 我是CUDA的新手.如何分配大小为MXN的2D数组?如何在CUDA中遍历该数组?给我一个示例代码................................................... ..........................................
嗨..谢谢你的回复.我在下面的程序中使用了你的代码.但我没有得到正确的结果.
__global__ void test(int A[BLOCK_SIZE][BLOCK_SIZE], int B[BLOCK_SIZE][BLOCK_SIZE],int C[BLOCK_SIZE][BLOCK_SIZE])
{
int i = blockIdx.y * blockDim.y + threadIdx.y;
int j = blockIdx.x * blockDim.x + threadIdx.x;
if (i < BLOCK_SIZE && j < BLOCK_SIZE)
C[i][j] = A[i][j] + B[i][j];
}
int main()
{
int d_A[BLOCK_SIZE][BLOCK_SIZE];
int d_B[BLOCK_SIZE][BLOCK_SIZE];
int d_C[BLOCK_SIZE][BLOCK_SIZE];
int C[BLOCK_SIZE][BLOCK_SIZE];
for(int i=0;i<BLOCK_SIZE;i++)
for(int j=0;j<BLOCK_SIZE;j++)
{
d_A[i][j]=i+j;
d_B[i][j]=i+j;
}
dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);
dim3 dimGrid(GRID_SIZE, GRID_SIZE);
test<<<dimGrid, dimBlock>>>(d_A,d_B,d_C);
cudaMemcpy(C,d_C,BLOCK_SIZE*BLOCK_SIZE , cudaMemcpyDeviceToHost);
for(int i=0;i<BLOCK_SIZE;i++)
for(int j=0;j<BLOCK_SIZE;j++)
{
printf("%d\n",C[i][j]);
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我.
使用cvShowImage,可以在OpenCV中轻松显示图像.但是,您如何告诉OpenCV在每个其他窗口的顶部显示窗口?
我在显示图像的同时运行全屏OpenGL应用程序.第一次OpenCV窗口弹出我的应用程序窗口,但如果我点击我的应用程序的窗口(即重点关注它),那么我无法让OpenCV回到顶部OpenGL窗口,即使在销毁和重新创建窗口时也是如此.
我想过每次重命名窗口,但还有另一种方法吗?