Build error when using OpenGL in my program - eclipse

I'm using the following code (which I found on the web) to create a basic OpenGL program:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#define window_width 640
#define window_height 480
// Main loop
void main_loop_function()
{
// Z angle
static float angle;
// Clear color (screen)
// And depth (used internally to block obstructed objects)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
.
.
.
}
.
.
.
I'm using Ubuntu 12.04 and Eclipse 3.7.2. The program compiles and actually runs, but strangely I get an error showing up in my code. The
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
line has the error:
Multiple markers at this line
- Invalid arguments ' Candidates are: void glClear(unsigned int) '
- Symbol 'GL_COLOR_BUFFER_BIT' could not be resolved
- Symbol 'GL_DEPTH_BUFFER_BIT' could not be resolved
Everything I've tried so far does not remove this error from the IDE. Any help would be welcomed.
NB if I change the line to
glClear(GL_COLOR_BUFFER_BIT);
or
glClear(GL_DEPTH_BUFFER_BIT);
then the error goes away...

I solved this problem by activating "Preferences -> C/C++ -> Indexer -> Use active build configuration" and then rebuilding the project. It now finds the symbol.

Related

Is there a way to get possible characters for a image (containing single character) in tesseract?

I tried searching around in the internet, github issues and such, but was unable to find if it's possible to get the result with different possible character alternatives while using tesseract.
for example while running tesseract -l jpn --psm 10 input.png - on this image I get the output 白, but if possible I'd like to also see the other possibilities, and if possible with their confidence coefficients.
I found that it's specially useful while trying to recognize a single character as the tesseract --psm 10 will give wrong but close results for complex kanji.
Like was being recognized as 側. So, I was thinking if I could like get the 5 most probable or sth like that from the command line, then it could be great. And if it's not possible through the command line I'm also willing to see a direct programming approach using the API.
EDIT:
tesseract -l jpn --psm 10 iu.png - command on results in 雨 result. On doing this on the code given in the answer I can see that the confidence is 93.68% and shows only one result. If I run the same in this image instead , I'll get 言 (99.46%) which means it is giving a sensible result, but it's only giving me a single result ignoring others. I hypothesized that it does so because the confidence is high because if I run the same command on , I get 遊 but when I run the code, I get
遊 (71.77%)
遮 (67.41%)
遭 (66.76%)
避 (65.36%)
遷 (65.00%)
選 (64.70%)
透 (64.55%)
進 (64.52%)
適 (63.95%)
週 (63.22%)
Hence, I assume it's giving single result in previous images because it is confident.
Furthermore doing tesseract -l jpn_vert screenshot.png - in this image gives the output 言わない, which is correct, which means even when it gave me 雨 result on the cropped character in the same image, there was 言 match there but with lower coefficient but it came up when it was doing the dictionary match in the whole word (which removed 雨 as a possibility). That's why while trying to identify a single character, I want to get the output with all those matches (a fixed number or a threshold decided by myself).
The code I have is almost identical to the one given in the example I have only added whitelist characters (around 2000+ kanji). Had to remove api->SetVariable("tessedit_char_whitelist", ...) line because SO thought it was spam.
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <tesseract/publictypes.h>
int main(int argc, char *argv[]){
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with Japanese, without specifying tessdata path
if (api->Init(NULL, "jpn")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
// Open input image with leptonica library
Pix *image = pixRead(argv[1]);
api->SetImage(image);
api->SetVariable("save_blob_choices", "T");
api->SetPageSegMode(tesseract::PSM_SINGLE_CHAR);
api->Recognize(NULL);
tesseract::ResultIterator* ri = api->GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
if(ri != 0) {
do {
const char* symbol = ri->GetUTF8Text(level);
float conf = ri->Confidence(level);
if(symbol != 0) {
tesseract::ChoiceIterator ci(*ri);
do {
const char* choice = ci.GetUTF8Text();
printf("%s (%.2f%%)\n", choice, ci.Confidence());
} while(ci.Next());
}
delete[] symbol;
} while((ri->Next(level)));
}
// Destroy used object and release memory
api->End();
pixDestroy(&image);
return 0;
}
IMHO you will need to use tesseract API https://github.com/tesseract-ocr/tessdoc/blob/master/APIExample.md#example-of-iterator-over-the-classifier-choices-for-a-single-symbol

'Concurrency': a namespace with this name does not exist

I am an amateur C# programmer who strayed into C++ because of a need for the C++ AMP technology for some heavy-duty number crunching. Hence, my C++ programming skills are not very well developed.
For my first attempt at an actual program, I chose code based on a Daniel Moth's April 2012 article. I cannot get it to build. I always get the error:
C2871 ‘Concurrency’: a namespace with this name does not exist.
I know that the code was first written for Visual Studio 11, but I only had VS 2008 and VS 2010 on my machine. So, I installed VS 2017 (version 15.9.4, .Net 4.7.03062). I started with an empty C++ project but had trouble with it. The best I could do, after I worked through all the things it didn’t recognize, was an error:
C3861: ‘access’ identifier not found, line 2616 in file ‘amp.h’.
So I started again, this time with an empty Windows Console Application project. Again, I had to tweak the code considerably to migrate from Visual Studio 11 to VS 2017, but ended up with code as shown below.
I tried what I could to find the source of the error. I targeted both x64 and x86, but it made no difference. I commented out line 5 and lines 21 – 27, and the code would build and execute. IntelliSense showed no problems, either with identifiers or syntax. In fact, the mouse-over info recognized the Concurrency constructs as such. I deliberately misspelled Concurrency, but IntelliSense caught that right away. I looked through the project properties with an eye toward a setting that needed to be changed to run AMP, but as I wasn’t even sure what I was looking for, I didn’t find anything.
I tried to find the name of the file in which Concurrency is defined, so that I could search my machine to see if it was there, and to add a path if it was, but was unsuccessful. I couldn’t even find the file name. I googled and pored through on-line sources and MS Docs, but no matter how I phrased my search questions, I didn’t find any answers.
The error says:
Concurrency does not exist
which to me means it can’t find it, it’s not on the machine, or some build setting is preventing it from being used. Most of the on-line articles about writing AMP code say nothing about build settings. Does it not require anything different than a serially-coded project? Is it as simple as a missing reference? If so, where do I go to find it? With my limited experience, I don’t know what else to try.
My machine is a Win 7 SP1 box. The KB2999226 bug fix has been installed. I didn’t install all of VS 2017 since I am only interested in C# and C++. Did I fail to install something I should have?
If this problem was addressed before, I couldn’t find it. So, any help would be appreciated.
1. #include <amp.h>
2. #include "pch.h"
3. #include <iostream>
4. #include <vector>
5. using namespace Concurrency;
6.
7. int main() {
8. const int M = 1024; const int N = 1024; //row, col for vector
9. std::vector<int> vA(M*N); std::vector<int> vB(M*N); //vectors to add
10. std::vector<int> vC(M*N); //vector for result
11.
12. for (int i = 0; i < M; i++) { vA[i] = i; } //populate vectors
13. for (int j = N - 1; j >= 0; j--) { vB[j] = j; }
14.
15. for (int i = 0; i < M; i++) { //serial version of
16. for (int j = 0; j < N; j++) { //matrix addition
17. vC[i*N + j] = vA[i*N + j] + vB[i*N + j]; //using vectors
18. }
19. }
20.
21. extent<2> e(M, N); //uses AMP constructs but no
22. array_view<int, 2> a(e, vA), b(e, vB); //parallel functions invoked
23. array_view<int, 2> c(e, vC);
24. index<2> idx(0, 0);
25. for (idx[0] = 0; idx[0] < e[0]; idx[0]++) {
26. for (idx[1] = 0; idx[1] < e[1]; idx[1]++) {
27. c[idx] = a[idx] + b[idx];
28. }
29. }
30. // C2871 'Concurrency': a namespace with this name does not exist. Line 5
31. // Also C2065, C3861, C2062 for all Concurrency objects Line 21 - Line 27
32. }
33.
With,
#include "amp.h"
#include "pch.h"
#include <iostream>
using namespace concurrency;
I get,
C2871 'concurrency': a namespace with this name does not exist
However, with,
#include "pch.h"
#include <iostream>
#include "amp.h"
using namespace concurrency;
there is no error.
I suggest moving #include "amp.h" as shown.
I also used both concurrency and Concurrency. There was no difference.
For the error C3861: ‘access’ identifier not found, line 2616 in file ‘amp.h’.
From the menu, select Project, then select Properties.
In the Property Pages window, under C/C++, select All Options, then select Conformance mode.
Change Yes (/permissive-) to No. Select OK.
Build the project and run.
By default, the /permissive- option is set in new projects created by Visual Studio 2017 version 15.5 and later versions. It is not set by default in earlier versions. When the option is set, the compiler generates diagnostic errors or warnings when non-standard language constructs are detected in your code, including some common bugs in pre-C++11 code.
More information may be found here.
This suggests, to me, that "amp.h" is not conforming to the changes made to C++ 15.5. Thus it worked with C++ in VS 2015 14.0 (Update 3), then failed with C++ in VS 2017 15.9.5.

Eclipse Nsight CDT plugin pressing F3 to Open Declaration goes to the wrong line

Nsight Eclipse Edition
Version: 5.5.0
CDT version: 8.1.2.nvidia-qualifier
Quick reference upon mouse over pops up the wrong declaration. Usually it's a function, which is located at the same header file, as the one I'm looking for, but it has no relation to it so far. For example:
For cudaMemcpy() it shows me this function from "cuda_runtime_api.h":
extern __host__ cudaError_t CUDARTAPI cudaPointerGetAttributes(struct cudaPointerAttributes *attributes, void *ptr);
For cudaMalloc() it gives me the description of:
extern __host__ cudaError_t CUDARTAPI cudaMemcpy2DToArray(struct cudaArray *dst, size_t wOffset, size_t hOffset, const void *src, size_t spitch, size_t width, size_t height, enum cudaMemcpyKind kind);
Why is indexing behaving this way? I'm getting tired of it after a couple of days working, but still couldn't find any obvious solution for this issue.
I will log this issue in our issue tracker. Sorry for the inconvenience. There is no workaround available.
Note that for performance reasons, Nsight does not index those files on your system. Instead, it comes prepackaged with compiled index files - apparently some headers might be different from the versions Nsight index was built from.

8051 include file setting in eclipse

I am running Eclispe IDE Kepler C/C++Developers, because I would like to programming a 8051 based microcontroller. I start Eclipse, File>New>C Project. Select MCS51 family (SDCC) under Project type and SDCC Tool Chain under Toolchains. Click next, leave Release and Debug selected, click Finish. The project is created. I want to try a simple code:
#include <8051.h>
void delay()
{
int i,j;
for (i = 0;i<=100;i++)
for (j = 0;j<=100;j++);
}
void main()
{
while (1)
{
P1_0 =0; // led glow
delay();
P1_0 = 1; // led off
delay();
}
}
When I build it there was a question mark before #inlude<8051.h> , and when I double click on it, I had got a messsage: No Inludes Found, "No include files were found that matched that name."
So, as I think Eclipse did not find the 8051 header file. I tried to find an example how to solve this problem, but I failed. The question is how to set the right path for 8051.h? If anyone of you can offer me a right solution I would be greatful.
Inside the folder where the toolchain is installed, you should have a folder called "include". Check if 8051.h is in the "root" folder, inside /include. If not, look for it. You must add the path to the include. Let's say the file is in /arch/8051.h, your include becomes:
#include <arch/8051.h>
void delay()
{
//stuff

problem with nvmex in matlab

i have installed matlab on my system and also have installed the CUDA SDK for windows. however i am not able to compile any .cu files. I have included the nvmex script file in the bin directory of the Matlab installation path. Can some body help?
nvmex isn't really supported in any recent versions of Matlab or the Cuda SDK. Instead, I would suggest writing a simple DLL in Visual Studio which uses the standard MEX interface to run Cuda. I'm going to assume that your project is called "addAtoB" and that you just want to add two numbers together to make the example simpler.
When you installed the Cuda SDK, you need to tell it to add the CUDA Custom Build Rules to Visual Studio so that it will know how to compile .CU files.
Your main cpp should look something like this:
// addAtoB.cpp
#include <mex.h>
#include <cuda.h>
#include <driver_types.h>
#include <cuda_runtime_api.h>
#pragma comment(lib,"libmx.lib") // link with the Matlab MEX API
#pragma comment(lib,"libmex.lib")
#pragma comment(lib,"cudart.lib") // link with CUDA
// forward declare the function in the .cu file
void runMyCUDAKernel(void);
// input and output variables for the function in the .cu file
float A, B, C;
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
A = (float) mxGetScalar(prhs[0]);
B = (float) mxGetScalar(prhs[1]);
runMyCUDAKernel();
// allocate output
nlhs = 1;
plhs[0] = mxCreateDoubleScalar(C);
mexPrintf("GPU: %f + %f = %f\nCPU: %f", A, B, C, A+B);
cudaDeviceReset();
}
You need add several directories to your Include Path: C:\Program Files\MATLAB\R2009a\extern\include and the CUDA directories.
Add to your Linker Path: C:\Program Files\MATLAB\R2009a\extern\lib\win32\microsoft , $(CUDA_PATH)\lib\$(PlatformName)
Next, add a .DEF file to your project which looks something like this:
LIBRARY "addAtoB"
EXPORTS
mexFunction
Next, create a file called runMyCUDAKernel.cu in the current directory, type in contents something like this, and then add the file to your project:
// runMyCUDAKernel.cu:
#include <cuda.h>
extern float A, B, C;
// Device kernel
__global__ void addAtoB(float A1, float B1, float* C1)
{
*C1 = A1+B1;
}
void runMyCUDAKernel(void)
{
float* pOutput;
cudaMalloc( (void**) &pOutput, 1*sizeof(float));
dim3 dimBlock(1, 1);
dim3 dimGrid(1, 1);
addAtoB<<< dimGrid, dimBlock >>>(A, B, pOutput);
cudaMemcpy( &C, pOutput, 1*sizeof(float), cudaMemcpyDeviceToHost);
cudaDeviceSynchronize();
cudaFree(pOutput);
}
Build the DLL and rename it from .dll to .mexw32 (or .mexw64, if you're using a 64-bit Matlab). Then you should be able to run it with the command addAtoB(1, 2).
I would suggest using CUDA mex from the Matlab file exchange.
It enables you to compile through Matlab. This gets better compatibility across Matlab and Visual Studio versions by not forcing you to specify the mex dependencies explicitly through Visual Studio.