我如何解决平面问题?当我建立它显示成功但程序没有运行。 [英] How Do I Solve Here Plane Problem?When I Do Build It Is Showing Succeeded But The Program Not Run.

查看:74
本文介绍了我如何解决平面问题?当我建立它显示成功但程序没有运行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include     opencv2 / imgproc / imgproc.hpp 
#include opencv2 / highgui / highgui.hpp
#include < stdlib.h >
#include opencv2 / core / core.hpp
#include opencv2 / imgproc / imgproc.hpp
#include < span class =code-preprocessor> < iostream >

使用 命名空间 cv;

/// 全局变量

Mat src,src_gray;
Mat dst,detected_edges,padded;

int edgeThresh = 1 ;
int lowThreshold;
int const max_lowThreshold = 100 ;
int ratio = 3 ;
int kernel_size = 3 ;
char * window_name = Edge Map ;

/ * *
* @function CannyThreshold
* @brief Trackbar回调 - Canny阈值输入比例为1:3
* /

void CannyThreshold( int void *)
{
/// 使用内核降低噪音3x3
模糊(src_gray,detected_edges,大小( 3 3 ));

/// Canny detector
Canny(detected_edges,detected_edges ,lowThreshold,lowThreshold * ratio,kernel_size);

/// 使用Canny的输出作为掩码,我们显示结果
dst = Scalar :: all( 0 );

src.copyTo(dst,detected_edges);
imshow(window_name,dst);

/// 通过按键
等待用户退出程序


int m = getOptimalDFTSize(dst.rows);
int n = getOptimalDFTSize(dst.cols);边框上的 // 添加零值
copyMakeBorder(dst,padded, 0 ,m - dst.rows, 0 ,n - dst.cols,BORDER_CONSTANT,Scalar :: all( 0 ));

Mat planes [] = {Mat_< float>(填充),Mat :: zeros(padded.size(),CV_32F)};
Mat complexdst;
merge(飞机, 2 ,complexdst); // 使用零添加到展开的另一个平面

dft(complexdst, complexdst); // 这样结果可能适合源矩阵

// 计算幅度并切换到对数刻度
// => log(1 + sqrt(Re(DFT(I))^ 2 + Im(DFT(I))^ 2))
split(complexdst,planes); // planes [0] = Re(DFT(I),planes [1] = Im(DFT(I))
幅度(飞机[ 0 ],飞机[ 1 ],飞机[ 0 ]); // planes [0] =幅度
Mat dst = planes [ 0 ];

dst + = Scalar :: all( 1 ); // 切换到对数刻度
log(dst,dst);

// 裁剪频谱,如果它有奇数行或列
dst = dst(Rect( 0 0 ,dst.cols& - 2 ,dst.rows& - 2 ));

// 重新排列傅里叶图像的象限,使原点位于图像中心
int cx = dst.cols / 2;
int cy = dst.rows / 2;

Mat q0(dst,Rect( 0 0 ,cx,cy )); // 左上角 - 每个象限创建一个ROI
Mat q1(dst,Rect( cx, 0 ,cx,cy)); // 右上角
Mat q2(dst,Rect( 0 ,cy,cx,cy)); // 左下角
Mat q3(dst,Rect(cx,cy,cx, CY)); // Bottom-Right

Mat tmp; // 交换象限(左上角和右下角)
q0.copyTo(tmp );
q3.c​​opyTo(q0);
tmp.copyTo(q3);

q1.copyTo(tmp); // 交换象限(右上角与左下角)
q2.copyTo(q1 );
tmp.copyTo(q2);

normalize(dst,dst, 0 1 ,CV_MINMAX); // 使用浮点值将矩阵转换为
// 可查看的图像格式(在值0和1之间浮动)。
imshow( 频谱幅度,dst);
}


/ * * @function main * /
int main( int argc, char ** argv)

{
/// 加载图片
src = imread( .JPG);
resize(src,src,Size(), 0 2 0 2 ,INTER_LANCZOS4);


/// 创建与src相同类型和大小的矩阵(对于dst)
dst.create(src.size(),src.type());

/// 将图像转换为灰度
cvtColor( src,src_gray,CV_BGR2GRAY);

/// 创建一个窗口
namedWindow(window_name, CV_WINDOW_AUTOSIZE);

/// 创建一个跟踪栏,供用户输入阈值
createTrackbar( 最小阈值:,window_name,& lowThreshold,max_lowThreshold,CannyThreshold);

/// 显示图片
CannyThreshold( 0 0 );

/ * ............... end of Fourier transfrom ....... * /
waitKey( 0 );

return 0 ;
}

解决方案

程序未运行不是一个有用的错误描述 - 它有点像你的车坏了在不知名的地方,你打电话给车库:我的车坏了。这是一个蓝色的福特节日并把手机放下。

这告诉机械师什么都没用 - 就像你在哪里或者是什么问题可能是。结果,你会坐在那里等待很长时间才能看到这些零件...



那么你需要做什么呢?使用调试器并找出它做了什么,以及它没有做什么。当你知道这一点时,很可能你的问题很明显。

在Main函数的顶部加一个断点,然后逐步执行你的程序:看看它在做什么,然后工作你认为它应该做什么。在某些时候,两者会有所不同,你应该专注于那个区域以找出原因。


但我们不能为你做到这一点!

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>

using namespace cv;

/// Global variables

Mat src, src_gray;
Mat dst, detected_edges,padded;

int edgeThresh = 1;
int lowThreshold;
int const max_lowThreshold = 100;
int ratio = 3;
int kernel_size = 3;
char* window_name = "Edge Map";

/**
 * @function CannyThreshold
 * @brief Trackbar callback - Canny thresholds input with a ratio 1:3
 */
void CannyThreshold(int, void*)
{
  /// Reduce noise with a kernel 3x3
  blur( src_gray, detected_edges, Size(3,3) );

  /// Canny detector
  Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

  /// Using Canny's output as a mask, we display our result
  dst = Scalar::all(0);

  src.copyTo( dst, detected_edges);
  imshow( window_name, dst );
  
  /// Wait until user exit program by pressing a key


    int m = getOptimalDFTSize( dst.rows );
    int n = getOptimalDFTSize( dst.cols ); // on the border add zero values
    copyMakeBorder(dst, padded, 0, m - dst.rows, 0, n - dst.cols, BORDER_CONSTANT, Scalar::all(0));

    Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
    Mat complexdst;
    merge(planes, 2, complexdst);         // Add to the expanded another plane with zeros

    dft(complexdst, complexdst);            // this way the result may fit in the source matrix

    // compute the magnitude and switch to logarithmic scale
    // => log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2))
    split(complexdst, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
    magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
    Mat dst = planes[0];

    dst += Scalar::all(1);                    // switch to logarithmic scale
    log(dst,dst);

    // crop the spectrum, if it has an odd number of rows or columns
    dst = dst(Rect(0, 0, dst.cols & -2, dst.rows & -2));

    // rearrange the quadrants of Fourier image  so that the origin is at the image center
    int cx = dst.cols/2;
    int cy = dst.rows/2;

    Mat q0(dst, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant
    Mat q1(dst, Rect(cx, 0, cx, cy));  // Top-Right
    Mat q2(dst, Rect(0, cy, cx, cy));  // Bottom-Left
    Mat q3(dst, Rect(cx, cy, cx, cy)); // Bottom-Right

    Mat tmp;                           // swap quadrants (Top-Left with Bottom-Right)
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);

    q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)
    q2.copyTo(q1);
    tmp.copyTo(q2);

    normalize(dst, dst, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
                                            // viewable image form (float between values 0 and 1).
 imshow("spectrum magnitude", dst);
 }


/** @function main */
int main( int argc, char** argv )
	
{
  /// Load an image
  src = imread(".JPG");
	resize(src, src, Size(), 0.2, 0.2, INTER_LANCZOS4);

 
  /// Create a matrix of the same type and size as src (for dst)
  dst.create( src.size(), src.type() );

  /// Convert the image to grayscale
  cvtColor( src, src_gray, CV_BGR2GRAY );

  /// Create a window
  namedWindow( window_name, CV_WINDOW_AUTOSIZE );

  /// Create a Trackbar for user to enter threshold
  createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

  /// Show the image
  CannyThreshold(0, 0);

 /*............... end of Fourier transfrom .......*/
  waitKey(0);

  return 0;
  }

解决方案

"The Program Not Run" is not a helpful error description - it's a bit like your car breaking down in the middle of nowhere and you calling the garage: "My car broke. It's a blue ford fiesta" and putting the phone down.
That tells the mechanics nothing useful - like where you are or what the problem might be. As a result, you would be sitting there waiting for a very long time before they turned up with the parts...

So what you need to do it start by using the debugger and finding out what it does do, and what it doesn't. When you know that, it is likely that the problem will be obvious to you.
Put a breakpoint at the top of the Main function, and step through your program: watch what it is doing, and work out what you think it should be doing. At some point the two will differ and that should hep you to focus on that area to find out why.

But we can't do that for you!


这篇关于我如何解决平面问题?当我建立它显示成功但程序没有运行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆