GNU Radio make error : "reference to ‘uhd’ is ambiguous" - c++

I created a bpsk flowgraph in gnuradio companion (grc) and it is working fine. At the moment Im writing a C++ equivalent of the same program using gnuradio classes. First I read the I/Q data from a file and I was able to get all the bpsk-modulated AX.25 frames. Now im trying to replace the file source block with a UHD one in order to be able to read the I/Q data in real time. make reports an error "reference to ‘uhd’ is ambiguous". The full make output is shown below
$ make
[ 50%] Building CXX object CMakeFiles/bpsk.dir/bpsk.cc.o
/home/mbkitine/Dropbox/Lulea/GRC/SSC/PSK/bpsk/RX_C++/bpsk.cc: In function ‘int main(int, char**)’:
/home/mbkitine/Dropbox/Lulea/GRC/SSC/PSK/bpsk/RX_C++/bpsk.cc:85:78: error: reference to ‘uhd’ is ambiguous
gr::uhd::usrp_source::sptr uhd_source = gr::uhd::usrp_source::make(address,uhd::stream_args_t("fc32"));
^
In file included from /usr/local/include/uhd/types/metadata.hpp:22:0,
from /usr/local/include/uhd/stream.hpp:22,
from /usr/local/include/uhd/device.hpp:22,
from /usr/local/include/uhd/usrp/multi_usrp.hpp:37,
from /usr/local/include/gnuradio/uhd/usrp_block.h:28,
from /usr/local/include/gnuradio/uhd/usrp_source.h:26,
from /home/mbkitine/Dropbox/Lulea/GRC/SSC/PSK/bpsk/RX_C++/bpsk.cc:56:
/usr/local/include/uhd/types/time_spec.hpp:25:14: note: candidates are: namespace uhd { }
namespace uhd{
^
In file included from /usr/local/include/gnuradio/uhd/usrp_source.h:26:0,
from /home/mbkitine/Dropbox/Lulea/GRC/SSC/PSK/bpsk/RX_C++/bpsk.cc:56:
/usr/local/include/gnuradio/uhd/usrp_block.h:31:17: note: namespace gr::uhd { }
namespace uhd {
^
CMakeFiles/bpsk.dir/build.make:62: recipe for target 'CMakeFiles/bpsk.dir/bpsk.cc.o' failed
make[2]: *** [CMakeFiles/bpsk.dir/bpsk.cc.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/bpsk.dir/all' failed
make[1]: *** [CMakeFiles/bpsk.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Here is my bpsk.cc code
// Include header files for each block used in flowgraph
#include <gnuradio/top_block.h>
#include <gnuradio/analog/sig_source_f.h>
#include <gnuradio/analog/agc2_cc.h>
#include <gnuradio/digital/fll_band_edge_cc.h>
#include <gnuradio/digital/pfb_clock_sync_ccf.h>
#include <gnuradio/filter/firdes.h>
#include <gnuradio/digital/cma_equalizer_cc.h>
#include <gnuradio/digital/costas_loop_cc.h>
#include <gnuradio/blocks/api.h>
#include <gnuradio/sync_block.h>
#include <gnuradio/digital/binary_slicer_fb.h>
#include <gnuradio/digital/diff_decoder_bb.h>
#include <gnuradio/digital/hdlc_deframer_bp.h>
#include <gnuradio/blocks/message_debug.h>
#include <gnuradio/audio/sink.h>
#include <gnuradio/blocks/file_source.h>
#include <gnuradio/uhd/usrp_source.h>
#include <ais/invert.h>
#include <gnuradio/blocks/complex_to_real.h>
#include <iostream>
#include <string>
using namespace gr;
int main(int argc, char **argv)
{
//Extracting variables from the menu
char* filename = argv[1];
//UHD Default parameters
double samp_rate = 1000000;
double baud_rate = 250000;
double fc = 100e6;
int sps = int(samp_rate/baud_rate);
//Receiver parameters
int dec = 10;
float loop_bw = 2 * 3.14/100;
// Construct a top block that will contain flowgraph blocks. Alternatively,
// one may create a derived class from top_block and hold instantiated blocks
// as member data for later manipulation.
top_block_sptr tb = make_top_block("bpsk");
//UHD block
std::string address = "192.168.10.2";
gr::uhd::usrp_source::sptr uhd_source = gr::uhd::usrp_source::make(address,uhd::stream_args_t("fc32"));
uhd_source->set_samp_rate(samp_rate);
uhd_source->set_center_freq(fc);
//Reading bpsk signal from file
//blocks::file_source::sptr file = blocks::file_source::make(sizeof(gr_complex),filename,false);
//Automatic gain controller
analog::agc2_cc::sptr agc = analog::agc2_cc::make(1e-1, 1e-2, 1.0, 1.0);
//FLL band edge filter
digital::fll_band_edge_cc::sptr fll = digital::fll_band_edge_cc::make(sps, 0.5, 44, loop_bw);
//PFB symbol time recovery
const int nfilts = 32;
std::vector<float> rrc_taps = filter::firdes::root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts);
digital::pfb_clock_sync_ccf::sptr pfb = digital::pfb_clock_sync_ccf::make(sps,loop_bw,rrc_taps,nfilts,0,1.5,2);
//CMA equalization
digital::cma_equalizer_cc::sptr cma = digital::cma_equalizer_cc::make(15,1,0.01,2);
//Costas loop
digital::costas_loop_cc::sptr costas = digital::costas_loop_cc::make(loop_bw,2);
//Taking the real part
gr::blocks::complex_to_real::sptr comp_to_real = blocks::complex_to_real::make(1);
//Binary slicer
digital::binary_slicer_fb::sptr slicer = digital::binary_slicer_fb::make();
//Differential decoder
digital::diff_decoder_bb::sptr differential_decoder = digital::diff_decoder_bb::make(2);
//Inverting bit values
//invert::sptr inverter = ais::invert::make();
//HDLC Deframer
digital::hdlc_deframer_bp::sptr deframer = digital::hdlc_deframer_bp::make(32,500);
//Output data
gr::blocks::message_debug::sptr msg = gr::blocks::message_debug::make();
std::cout << "Blocks declared successfully " << std::endl;
//Connections
tb->connect(uhd_source,0,agc,0);
tb->connect(agc,0,fll,0);
tb->connect(fll,0,pfb,0);
tb->connect(pfb,0,cma,0);
tb->connect(cma,0,costas,0);
tb->connect(costas,0,comp_to_real,0);
tb->connect(comp_to_real,0,slicer,0);
tb->connect(slicer,0,differential_decoder,0);
tb->connect(differential_decoder,0,deframer,0);
//tb->connect(inverter,0,deframer,0);
tb->msg_connect(deframer,"out",msg,"print_pdu");
tb->run();
std::cout << "The GNU Radio Thread is Running " << std::endl;
// Exit normally.
return 0;
}
And finally my CMakelists.txt file. I basically modified this file from the original dialtone C++ example which can be found in {YOUR_GNURADIO_DIRECTORY}/gr-audio/examples/c++
cmake_minimum_required(VERSION 2.6)
project(bpsk CXX)
find_package(Boost "1.35" COMPONENTS system)
set(GR_REQUIRED_COMPONENTS RUNTIME ANALOG AUDIO BLOCKS FILTER DIGITAL UHD)
find_package(Gnuradio "3.7.2" REQUIRED)
include_directories(${GNURADIO_ALL_INCLUDE_DIRS})
add_executable(bpsk bpsk.cc)
target_link_libraries(bpsk ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES})
Any help will be highly appreciated.
Regards
Moses.

The error says what's wrong right there:
since you're doing
using namespace gr;
you compiler can't know whether you mean gr::uhd or just uhd.
I'd just recommend dropping the using namespace gr directive. Or, using ::uhd when you really mean the non-gr:: namespace.

Related

Including the Geos library into a new Visual Studio project

It's been years since I used C++ and so I'm very rusty. I'm trying to test out the Geos library, but I'm unable to get a simple Hello World example to compile
https://libgeos.org/usage/download/
This is what I tried:
I downloaded and extracted the files
Created a new C++ project in Visual Studio
Added the headers folder into the Visual Studio Include Directories for the project.
Then I tried to use the library in my main.cpp:
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <iostream>
#include <memory>
geos::geom::Polygon * MakeBox(double xmin, double ymin, double xmax, double ymax) {
std::unique_ptr<geos::geom::PrecisionModel> pm(new geos::geom::PrecisionModel());
geos::geom::GeometryFactory::unique_ptr factory = geos::geom::GeometryFactory::create(pm.get(), -1);
geos::geom::CoordinateSequence* temp = factory->getCoordinateSequenceFactory()->create((std::size_t)0, 0);
temp->add(geos::geom::Coordinate(xmin, ymin));
temp->add(geos::geom::Coordinate(xmin, ymax));
temp->add(geos::geom::Coordinate(xmax, ymax));
temp->add(geos::geom::Coordinate(xmax, ymin));
//Must close the linear ring or we will get an error:
//"Points of LinearRing do not form a closed linestring"
temp->add(geos::geom::Coordinate(xmin, ymin));
geos::geom::LinearRing* shell = factory->createLinearRing(temp);
//NULL in this case could instead be a collection of one or more holes
//in the interior of the polygon
return factory->createPolygon(shell, NULL);
}
int main() {
geos::geom::Polygon* box = MakeBox(0, 0, 10, 10);
std::cout << box->getArea() << std::endl;
delete box; //Important to avoid memory leaks
}
I'm getting multiple errors, but they all seem to indicate that the library is not loaded correctly
Severity Code Description Project File Line Suppression State Error
(active) E0135 class "geos::geom::GeometryFactory" has no member
"unique_ptr" TestGeos C:\TestGeos\TestGeos.cpp 15
What am I missing in order to use the library?

C++ YOLOv5: Failed to parse onnx model in function 'cv::dnn::dnn4_v20190621::ONNXImporter::ONNXImporter'

I want to use YOLOv5 for object detection Using C++ and OpenCV's DNN.
I'm using Windows 10, and VS 2019.
However, the following line of code:
#include <opencv2/opencv.hpp>
int main(int, char **)
{
auto net = cv::dnn::readNet("yolov5s.onnx");
return 0;
}
causes the following error:
OpenCV(4.1.1) C:\opencv-4.1.1\modules\dnn\src\onnx\onnx_importer.cpp:57: error: (-210:Unsupported format or combination of formats) Failed to parse onnx model in function 'cv::dnn::dnn4_v20190621::ONNXImporter::ONNXImporter'
Press any key to continue . . .
EDIT:
Seems there was a problem with the path.
After I wrote the full path to the full .onnx file path, as follows:
#include <opencv2/opencv.hpp>
int main(int, char **)
{
auto net = cv::dnn::readNet("C:/Users/hedey/source/repos/Road_Defects_Detector/yolov5s.onnx");
return 0;
}
Now, I'm getting the following error:
OpenCV(4.1.1) C:\opencv-4.1.1\modules\dnn\src\onnx\onnx_importer.cpp:320: error: (-204:Requested object was not found) Blob not found in const blobs in function 'cv::dnn::dnn4_v20190621::ONNXImporter::getBlob'
Press any key to continue . . .

error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'

I am new to C++ and i am getting error like
error: no matching function for call to 'FaceDetector::FaceDetector(std::__cxx11::string)'
FaceDetector fd(string(DEFAULT_CASCADE_PATH));
and i am attaching my code and error log how to fix this please guide me
#define DEFAULT_CASCADE_PATH "cascades/haarcascade_frontalface_default.xml"
#define ORIGINALS_LIST "obama_raw/list"
#define OUTPUT_DIR "obama_faces"
#define OUTPUT_LIST "list"
#define FACE_SIZE Size(150,150)
#include <cstdlib>
#include <fstream>
#include "cv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "FaceDetector.h"
using namespace std;
using namespace cv;
void read_input_list(const string &list_path, vector<Mat> &images) {
ifstream file(list_path.c_str());
string path;
while (getline(file, path)) {
images.push_back(imread(path));
}
}
int main(int argc, char** argv) {
FaceDetector fd(string(DEFAULT_CASCADE_PATH));
vector<Mat> raw_faces;
ofstream out_list(format("%s/%s", OUTPUT_DIR, OUTPUT_LIST).c_str());
read_input_list(string(ORIGINALS_LIST), raw_faces);
int img_c = 0; //images counter
//now detect the faces in each of the raw images:
for (vector<Mat>::const_iterator raw_img = raw_faces.begin() ; raw_img != raw_faces.end() ; raw_img++){
vector<Rect> faces;
//detect faces in the image (there should be only one):
fd.findFacesInImage(*raw_img, faces);
//cut each face and write to disk:
for (vector<Rect>::const_iterator face = faces.begin() ; face != faces.end() ; face++){
int edge_size = max(face->width, face->height);
Rect square(face->x, face->y, edge_size, edge_size);
Mat face_img = (*raw_img)(square);
//resize:
resize(face_img, face_img, FACE_SIZE);
//write to disk:
string face_path = format("%s/%d.jpg", OUTPUT_DIR, img_c++);
imwrite(face_path,face_img);
out_list << face_path << endl;
}
}
out_list.close();
return 0;
}
and i am attaching my error log.Please can any one help.
Thanks in advance
Error : https://i.stack.imgur.com/RZXXK.jpg
From GCC 5, A new ABI is enabled by default. In that new ABI, std::__cxx11 namesapce was introduced.
According to your error message, It seems that your program and OpenCV library you want to link with were build with different GCC version, which made incompatible binary.
For more information, you can read the following page:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

error C3861: 'getGaborKernel': identifier not found

I am trying to build the following code, but It failed because of the following error
error C3861: 'getGaborKernel': identifier not found
I have included the required header files and lib files. What could be the problem?
#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <math.h>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
Mat in = imread("1.jpg",0); // load grayscale
Mat dest;
Mat src_f;
in.convertTo(src_f,CV_32F);
extern ostream cerr;
int kernel_size = 31;
double sig = 1, th = 0, lm = 1.0, gm = 0.02, ps = 0;
cv::Mat kernel =
getGaborKernel(cv::Size(kernel_size,kernel_size),sig, th, lm, gm,
ps);
cv::filter2D(src_f, dest, CV_32F, kernel);
cerr << dest(Rect(30,30,10,10)) << endl; // peek into the data
Mat viz;
dest.convertTo(viz,CV_8U,1.0/255.0);
imshow("k",kernel);
imshow("d",viz);
waitKey();
return 0;
}
When C++ misses a prototype it issues an error. Your source obviously didn't include the header file with the appropriate prototype or the prototype is hidden by #ifdefs.
Lookup the Header file that you expect that it contains the prototy of getGaborKernel.
Check the option Show includes to see what header files are actually included. Verify the header found in the first step is in the list.
Check the option Preprocess to a file to see what the preprocessor outputs after processing all #ifdefs in the generated .i file. Check why the prototype isn't in the output.
Uncheck both options after you have found the problem. That's important for the Preprocess to a file option to get a .obj file instead of the .i.

trouble with Open Cv and GPIO on mini6410

I am doing a simple project on arm based mini6410. I have debian package installed on mini. My project is to interface one IR motion sensor and I USB webcam with the mini6410. the working will be simple, whenever there will be any motion detected by IR sensor, the webcam will be on for 30 seconds save the images (over write the previous) and then off.
I have already cross comiled the Open CV code using arm-linux-gcc
For IR I am using GPE register.
Here I am stuck with a issue which I am unable to resolve. and even dont know how to resolve. OpenCv code is a cpp file camera.cpp and the file which deals with I/O ports is a C file named sensor.c. Now in that c file I am polling or whatever mechanism to check if the GPE register is 1 or not. If it is one, I should start the Open CV code which will start to capture images. further more this sensor.c file is not to be compiled rather made a module and then insmod on my mini6410.
However I dont know how to write c++ code in a c file. you can say i dont know how to call the OpenCV thing from the C file. as it is a module and within this i cant write the cpp code as then using namespace std and using namespace cv doesnot work.
i am new to embedded stuff and linux it self. so I wanted to know are there some possible solutions.
i am attaching my codes of both files.
This is sensor.c
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/serio.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <mach/map.h>
#include <mach/regs-clock.h>
#include <mach/regs-gpio.h>
#include <plat/gpio-cfg.h>
#include <mach/gpio-bank-q.h>
#include <mach/gpio-bank-e.h>
#include <mach/map.h>
#include <plat/regs-timer.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/moduleparam.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>
#include <mach/gpio-bank-k.h>
#define RLV 0x0FFF
unsigned Gpe;
unsigned sensor_value;
typedef struct
{
int delay;
} TIM_DEV;
static TIM_DEV TimDev;
static irqreturn_t INTHandler(int irq,void *TimDev)
{
Gpe = readl(S3C64XX_GPEDAT);
Gpe &= ~(0xF<<1);
readl(sensor_value, S3C64XX_GPEDAT);
while (sensor_value == 1)
{//1 means that IR sensor has detected a motion and given a value of +5 V
for (i = 0; i < 30; i++){
//CV_function();
// delay here such that delay(1 s) * 30 = 30 seconds
}
}
return IRQ_HANDLED;
}
static struct file_operations dev_fops = {
.owner = THIS_MODULE,
.write = MyWrite,
};
static struct miscdevice misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &dev_fops,
};
static int __init dev_init(void)
{
int ret;
unsigned TimerControl;
unsigned TimerINTControl;
unsigned TimerCNTB;
unsigned TimerCMPB;
unsigned TimerCFG1;
unsigned Ge;
TimerControl = readl(S3C_TCON);
TimerINTControl = readl(S3C_TINT_CSTAT);
TimerCNTB = readl(S3C_TCNTB(0));
TimerCMPB = readl(S3C_TCMPB(0));
TimerCFG1 = readl(S3C_TCFG1);
TimerCFG1 &= ~(S3C_TCFG1_MUX0_MASK);
TimerCNTB = RLV;
TimerCMPB = 0;
writel(TimerCNTB, S3C_TCNTB(0));
writel(TimerCMPB, S3C_TCMPB(0));
writel(TimerCFG1, S3C_TCFG1);
TimerControl |= S3C_TCON_T0MANUALUPD;
TimerINTControl |= S3C_TINT_CSTAT_T0INTEN;
writel(TimerControl, S3C_TCON);
writel(TimerINTControl, S3C_TINT_CSTAT);
TimerControl = readl(S3C_TCON);
TimerControl |= S3C_TCON_T0RELOAD;
TimerControl &= ~S3C_TCON_T0MANUALUPD;
TimerControl |= S3C_TCON_T0START;
writel(TimerControl, S3C_TCON);
//////////////Here I am configuring my GPE as input/////////////
Ge = readl(S3C64XX_GPECON);
Ge &= ~(0xFFFF<<4);
Ge |= (0x0000<<4);
writel(Ge, S3C64XX_GPECON);
/////////////
misc_register(&misc);
ret = request_irq(IRQ_TIMER0, INTHandler, IRQF_SHARED, DEVICE_NAME, &TimDev);
if (ret)
{
return ret;
}
return ret;
}
static void __exit dev_exit(void)
{
free_irq(IRQ_TIMER0, &TimDev);
misc_deregister(&misc);
}
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("XYZ");
this is camera.cpp
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{CvCapture* capture = 0;
Mat frame, frameCopy, image;
capture = cvCaptureFromCAM( 2 );
if( !capture )
{
cout << "No camera detected" << endl;
}
if( capture )
{
cout << "In capture ..." << endl;
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
break;
if( iplImg->origin == IPL_ORIGIN_TL )
frame.copyTo( frameCopy );
else
flip( frame, frameCopy, 0 );
cvSaveImage("image.jpg" ,iplImg);
}
cvReleaseCapture( &capture );
return 0;
}
the for loop in the sensor.c file should have my this above code by some means
I hope you get the idea,
Thanks
The missing link in the code shown is a mechanism by which the user-space code shown above can get notification of a change in the GPIO pin detected by the device driver.
There are two obvious ways to achieve this:
Integrate the GPIO pin into the platform's GPIO resources and then use the generic sysfs mechanism from user-space. The Linux kernel GPIO documentation describes both kernel and user-space side of this.
Have your driver expose a sysfs node for the GPIO line. sysfs is fundamental to the Linux Driver Model. I suggest a thorough read of Linux Device Drivers 3rd Edition.
The user-space side of either method is similar: You open the sysfs resource exported by your module and then use either poll() or select() to block until an event occurs.