简体   繁体   English

Visual Studio 2015 社区 - 未找到函数定义但可以编译

[英]Visual Studio 2015 community - Function definition not found but can compile

I have a project in visual studio 2015 community.我在 Visual Studio 2015 社区中有一个项目。 It compiles without any error but I get a green squiggly line under compute_edge_map_via_lab and compute_local_minima which says Function definition for "compute_edge_map_via_lab" not found .它编译时没有任何错误,但我在 compute_edge_map_via_lab 和 compute_local_minima 下有一条绿色波浪线,表示未找到“compute_edge_map_via_lab”的函数定义 I can right click on the line that calls compute_edge_map_via_lab and then I click on "Go to definition" it even brings me to the definition in the cpp file implying that visual studio knows where the function is defined.我可以右键单击调用 compute_edge_map_via_lab 的行,然后单击“转到定义”,它甚至将我带到 cpp 文件中的定义,这意味着 Visual Studio 知道函数的定义位置。 So I don't understand this green error.所以我不明白这个绿色错误。 Can anyone help me on this ?谁可以帮我这个事 ?

I have pasted the function for compute_edge_map_via_lab and the image showing the error.我已经粘贴了 compute_edge_map_via_lab 的函数和显示错误的图像。

在此处输入图片说明

#include <boost/heap/fibonacci_heap.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <unordered_set>

#include "image-processing.h"

int main {

cv::Mat image = imread("0001.jpg", CV_LOAD_IMAGE_COLOR);

//compute edge map
cv::Mat magnitude;
compute_edge_map_via_lab(image, magnitude);

//compute local minimas
cv::Mat markers;
compute_local_minima(magnitude, markers);
}

image-processing.h图像处理.h

#pragma once

#include <opencv2/opencv.hpp>

void compute_edge_map_via_lab(cv::Mat image, cv::Mat edge_map);
void compute_local_minima(cv::Mat magnitude, cv::Mat markers);

image-processing.cpp图像处理.cpp

#include "image-processing.h"

void compute_edge_map_via_lab(cv::Mat image, cv::Mat edge_map) {
int rows = image.rows;
int cols = image.cols;

//convert bgr to lab
cv::Mat image_lab;
cv::cvtColor(image, image_lab, CV_BGR2Lab);

//split lab
std::vector<cv::Mat> image_lab_split(3);
cv::split(image_lab, image_lab_split);

//run sobel x and y on lab sets
std::vector<cv::Mat> image_lab_split_dx(3), image_lab_split_dy(3);
for (int i = 0; i < 3; i++)
{
    cv::Sobel(image_lab_split[i], image_lab_split_dx[i], CV_32FC1, 1, 0, 3);
    cv::Sobel(image_lab_split[i], image_lab_split_dy[i], CV_32FC1, 0, 1, 3);
}

//-----------------------------------------------------------------------------
//compute magnitude = term_a            + term_b
//                  = sqrt(Lx^2 + Ly^2) + sqrt(2(ax^2 + ay^2 + bx^2 + by^2))
//-----------------------------------------------------------------------------

//compute sqrt(Lx^2 + Ly^2)
cv::Mat Lx_squared = cv::Mat(cv::Size(cols, rows), CV_32FC1),
    Ly_squared = cv::Mat(cv::Size(cols, rows), CV_32FC1);
cv::pow(image_lab_split_dx[0], 2, Lx_squared);
cv::pow(image_lab_split_dy[0], 2, Ly_squared);

//compute term_a
cv::Mat term_a = cv::Mat(cv::Size(cols, rows), CV_32FC1);
term_a = Lx_squared + Ly_squared;
cv::sqrt(term_a, term_a);

//compute sqrt(2(ax^2 + ay^2 + bx^2 + by^2))
cv::Mat ax_squared = cv::Mat(cv::Size(cols, rows), CV_32FC1),
    ay_squared = cv::Mat(cv::Size(cols, rows), CV_32FC1),
    bx_squared = cv::Mat(cv::Size(cols, rows), CV_32FC1),
    by_squared = cv::Mat(cv::Size(cols, rows), CV_32FC1);
cv::pow(image_lab_split_dx[1], 2, ax_squared);
cv::pow(image_lab_split_dy[1], 2, ay_squared);
cv::pow(image_lab_split_dx[2], 2, bx_squared);
cv::pow(image_lab_split_dy[2], 2, by_squared);

//compute term_b
cv::Mat term_b = 2 * (ax_squared + ay_squared + bx_squared + by_squared);
cv::sqrt(term_b, term_b);

//compute magnitude
edge_map = term_a + term_b;
}

void compute_local_minima(cv::Mat magnitude, cv::Mat markers) {

}

As far as the C++ standard is concerned, it doesn't matter: you can declare function prototypes without definitions so long as the functions are not called.就 C++ 标准而言,这无关紧要:只要不调用函数,您就可以声明没有定义的函数原型。

In the old days before C++11 this was even exploited: eg The introduction of a default constructor prototype to suppress unwanted construction.在 C++11 之前的旧时代,这甚至被利用:例如,引入默认构造函数原型来抑制不需要的构造。

Such cases are difficult for intellisense to spot - and perhaps it's a good thing that is does highlight them.这种情况很难被智能感知发现 - 也许这是一件好事,确实突出了它们。 (By the way, intellisense uses a different lexical analyser to the actual compiler!) (顺便说一句,intellisense 使用与实际编译器不同的词法分析器!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM