简体   繁体   中英

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

I have a project in visual studio 2015 community. 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 . 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. 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.

在此处输入图片说明

#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

#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

#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.

In the old days before C++11 this was even exploited: eg The introduction of a default constructor prototype to suppress unwanted construction.

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!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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