Tag Archives: c++

Error 1 error MSB3721: Command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe” -genco

Error 1 error msb3721: command “C:\program files\NVIDIA GPU computing toolkit\CUDA\v9.0\bin\nvcc. Exe” – gencode = arch = compute_ 20,code=“sm_ 20,compute_20” -gencode=arch=compute_ 30,code=“sm_30,compute_30” -gencode=arch=compute_50,code=“sm_50,compute_50” –use-local-env -ccbin “C:\Program Files
(cuda9.0targets 707)

Windows10 + cuda9.0 + cudnn + visual stdio2015 (originally, visual stdio2017 was used. Some blogs said no and changed it. If you downloaded 2017, you can directly change it at the change place. A single component will be OK under 2015. Some blogs talked about it and you can search it)

My computer graphics card version is gtx1050

After query, I changed compute and SM to compute_30,sm_30; compute_61,sm_ But it seems useless, but some bloggers say it’s useful, mainly because of different mistakes. You can try it.

I set the CUDA toolkit custom dir to C: \program files\NVIDIA GPU computing toolkit\CUDA at the beginning. When I opened the file, I found an error. It needs to be set to C: \program files\NVIDIA GPU computing toolkit\CUDA\v9.0

Then it’s solved. It’s been busy for two days. I’ve read a lot of blogs. I hope it can inspire you!!!

[Solved] Vs2015 error c2065: undeclared identifier error (__func__)

Problem: vs2015 compiles vtk8.2 with an error    Error c2065 undeclared identifier error (__ func__)

Solution: (two)

(1) Change the header file sequence online (the first method is tested, but it doesn’t work. It’s here temporarily, and the second method is effective)

#include "StdAfx.h"

Put it first

(2) Change,, name (test valid)

__func__ replace to __FUNCTION__

Test valid

C++ Opencv+BaiDu OCR“error“: “unsupported_grant_type“, “error_description“: “The authorization grant

1. Baidu general reference: authentication mechanism

https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjhhu

Introduction
this document is mainly for HTTP API callers. Baidu AIP open platform uses oauth2.0 authorization to call the open API. When calling the API, you must bring access in the URL_ Token parameter. The process of obtaining access token is as follows:

Get access token
request URL data format

To the authorized service address https://aip.baidubce.com/oauth/2.0/token Send the request (post is recommended), and take the following parameters in the URL:

grant_ Type: required parameter, fixed to client_ credentials;
client_ ID: required parameter, API key applied
client_ Secret: required parameter, the applied secret key;

https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=Va5yQRHlA4Fq5eR3LT0vuXV4&c

2. However, the result of my test is:

https://aip.baidubce.com/oauth/2.0/token

Postman test

{

    " grant_type": "client_credentials",

    "client_id": "pGB2vIVTXn9ATexEsqMIDYO",

   "client_secret": "5yNZqWSIuj4PVRGdavjw1e5U3z9K6Kb"

}

Get the token value and display the following results

{
    "error": "unsupported_grant_type",
    "error_description": "The authorization grant type is not supported"
}

Qttssessionbegin failed, error code: 25000 solution for Ubuntu development of iFLYTEK voice wake-up function

        The official error code is described as “the engine is not initialized”, so please first check whether it has been initialized, and then confirm that the link to libmsc.os and libw is entered at compile time_ ivw.os。 At this time, if 25000 is still reported as initialization error, you can set variables   LD_ LIBRARY_ Path solution:

1 open the. Bashrc file

sudo ./bashrc

2 add at the end of the file

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/PATH

Replace/path with libmsc.os and libw_ Ivw.os is the directory of two dynamic libraries. Save the changes.

Then close the command line window and reopen it to run.

How to Solve Nginx cross compilation Error

1.checking for C compiler … found but is not working
Modify auto/feature
find if [ -x $NGX_AUTOTEST ]; then
Assign the value in front of ngx_feature_run=no
2./configure: 1: auto/types/sizeof: objs/autotest: Exec format error
change auto/types/sizeof
find ngx_test=”$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs”
change $CC to gcc
3.objs/src/os/unix/ngx_user.o: In function `ngx_libc_crypt’: ngx_user.c:(.text+0x20): undefined reference to `crypt’
Find the ngx_libc_crypt function in src/os/unix/ngx_user.c:
change value = crypt((char *) key, (char *) salt);
to
value = DES_crypt((char *) key, (char *) salt);

[Solved] CAP_IMAGES: can‘t find starting number (in the name of file)

Solve cap_ IMAGES: can’t find starting number (in the name of file)

1. Solutions

1. Confirm that the output file type matches FourCC. For details, please refer to the official website http://www.fourcc.org/codecs.php 。
simply use. Avi with videowriter:: FourCC (‘m ‘,’ J ‘,’ p ‘,’ g ‘)
I found a post on the Internet saying that FourCC was used in the old version, but it’s not used now. It’s wrong. For opencv4.3. X, FourCC is still used. When compiling, add videowriter:: FourCC (‘x’, ‘x’, ‘x’, ‘x’) to the class name.

2. If step 1 is correct but still reports an error:
linux platform: reinstall ffmpeg, then recompile opencv and install it. When compiling opencv, cmake needs to add the parameter – dwith_ FFMPEG=ON。
window platform: the output file type can be changed to. MP4. This method is lazy and does not need to install ffmpeg.

The following explains in detail why the lazy law can take effect.

2. Error code

#define VIDEO_OUTPUT_PATH "D:\\test_project\\output.avi" 

int main()
{
	Mat frame;

	frame = imread("xxx.jpg");

	VideoWriter vWriter(VIDEO_OUTPUT_PATH, CAP_OPENCV_MJPEG, 30, Size(frame.cols, frame.rows));
	//Using CAP_OPENCV_MJPEG for the above parameters is wrong haha, VideoWriter::fourcc('M', 'J', 'P', 'G') is the correct parameter
	int frameNum = 90;  
	while (frameNum) {
		vWriter << dst;
		frameNum--;
	}

	return 0;
}
	

3. Error log

[ERROR:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\cap.cpp (563) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.1) C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): D:\\test_project\\output.avi in function 'cv::icvExtractPattern'

4. Error analysis

The above two sentences are error messages at runtime
the first sentence is the exception received when videowriter:: open is running
the second sentence is the specific exception content:

OpenCV(4.5.1) C:\build\master_ winpack-build-win64-vc14\opencv\modules\videoio\src\cap_ images.cpp:253: error: (-5:Bad argument) CAP_ IMAGES: can’t find starting number (in the name of file): D:\test_ Project \ output.avi in function ‘CV:: icvextractpattern’
we can get the following information from the error log:

    the error log is generated by the file cap_ Images.cpp line 253 is printed. It seems that there is a problem with the file name. Specifically, it is the </ OL> printed in the CV:: icvextractpattern function

Next, let’s look at the opencv source code and find out what’s wrong with my file name

5. Opencv source code analysis

//The icvExtractPattern function is found in opencv\modules\videoio\src\cap.cpp
std::string icvExtractPattern(const std::string& filename, unsigned *offset)
{
     size_t len = filename.size(); //record the length of the filename


	。。。。。。 // a bunch of operations, don't care


        pos = filename.rfind('/'); //find the last "/" in the file name
#ifdef _WIN32
        if (pos == std::string::npos)
            pos = filename.rfind('\\'); //for window systems, find the last "\\" in the filename
#endif
        if (pos ! = std::string::npos)
            pos++;
        else
            pos = 0;

        while (pos < len && !isdigit(filename[pos])) pos++; //key point of filename error

        if (pos == len) //throw exception if position is equal to filename length

Translated with www.DeepL.com/Translator (free version)
        {
            CV_Error_(Error::StsBadArg, ("CAP_IMAGES: can't find starting number (in the name of file): %s", filename.c_str()));
        }

}

The above code should find the file type to be output from the output file name
because the key point while (POS & lt; len && amp; ! isdigit(filename[pos])) pos++; The implementation here is that if the character referred to by POS in the file name is not a number, then POS will point to the next character with + +. It seems that the reason is to find the file name with number of children
therefore, an idea occurred. Set the file type of the output file to MP4, and then the problem was solved.

#define VIDEO_ OUTPUT_ PATH “D:\test_ Project \ output. Avi ”
is changed to:
#define video_ OUTPUT_ PATH “D:\test_ project\output.mp4”

If it is helpful, you may wish to praise and pay attention to support.

Template argument deduction/substitution failed: couldn‘t deduce template parameter [How to Solve]

Article catalog

Error code error reason solution

Error code

We want to implement a generic function to find the maximum value of the interval. The parameters are left and right iterators, which return the maximum value.

#include<iostream>
#include<vector>
using namespace std;
template<class T>
T findmax(typename vector<T>::iterator left,typename vector<T>::iterator right){
    T ret = *left;
    for (;left!=right;++left){
        ret = (*left)>ret ?*left : ret;     
    }
    return ret;
}

int main(){
    vector<int> a({3,4,6,2,1,5});
    cout << findmax(a.begin(),a.end());
    return 0;
}

error:
15:38: error: no matching function for call to ‘findmax(std::vector::iterator, std::vector::iterator)’
15 | cout << findmax(a.begin(),a.end());
5:3: note: candidate: ‘template T findmax(typename std::vector::iterator, typename std::vector::iterator)’
5 | T findmax(typename vector::iterator left,typename vector::iterator right){
5:3: note: template argument deduction/substitution failed:
15:38: note: couldn’t deduce template parameter ‘T’
15 | cout << findmax(a.begin(),a.end());

The reason
The compiler cannot guess that the template T is int based on the type vector< int >::iterator passed in

Solution
Specify the template manually at the place where the function is called.
Replace the used findmax with findmax< int >:

#include<iostream>
#include<vector>
using namespace std;
template<class T>
T findmax(typename vector<T>::iterator left,typename vector<T>::iterator right){
    T ret = *left;
    for (;left!=right;++left){
        ret = (*left)>ret ?*left : ret;     
    }
    return ret;
}

int main(){
    vector<int> a({3,4,6,2,1,5});
    cout << findmax<int>(a.begin(),a.end());
    return 0;
}

Run successfully

AVD FFmpeg avcodec_ A solution of open2 returning – 1 (operation not permitted)

I’m working on Android hard decoding recently. Various attempts have been made on the compatible implementation of soft decoding and hard decoding. Later, I suddenly found that it was unable to decode normally, and even failed to open codec appeared.

Use RET = avcodec_ Open2 (CTX, codec, nullptr) the return value is – 1, and the error message is “operation not permitted”. It’s a headache for me. For Android development, permissions, alas AVStream* st = pFormatCtx->streams[streamIdx]; codec_context_ = avcodec_alloc_context3(pCodec); if (!codec_context_) { AVLOGE("Failed to allocate the codec context."); return -1; } if (avcodec_parameters_to_context(codec_context_, st->codecpar) < 0) { AVLOGE("Failed to copy codec parameters to decoder context."); return -1; } if (enable_hw_decode_) { if (codec_context_->codec_id == AV_CODEC_ID_H264) { pCodec = avcodec_find_decoder_by_name("h264_mediacodec"); if (pCodec) { avcodec_free_context(&codec_context_); codec_context_ = avcodec_alloc_context3(pCodec); using_hw_decode_ = true; } } } int ret = 0; if ((ret = avcodec_open2(codec_context_, pCodec, nullptr)) < 0) { AVLOGE("Failed to open codec. ret = %d, %s", ret, PAVUtils::get_error_string(ret)); return -1; }

Because it was copied once at first, but later, if hard decoding was used, the coder was selected again. As a result, the newly applied avcodec context failed to copy the operation parameters from stream to context. When I was using_ hw_ decode_ = Add avcodec before true _ parameters_ to_ context(codec_ context_, st-> codecpar); and it will work normally
it's strange why the relevant parameters are not copied, instead of returning invalid_ Par returns no instead_ What about permit?

Grpc Compilation issues: “C++ versions less than C++11 are not supported.

# Official tutorial https://grpc.io/docs/languages/cpp/quickstart/
# mac compilation problems
“C++ versions less than C++11 are not supported.”
“`

# You need to add -DCMAKE_CXX_STANDARD=11 when compiling abseil, otherwise it will compile with an error

$ mkdir -p third_party/abseil-cpp/cmake/build
$ pushd third_party/abseil-cpp/cmake/build
$ cmake -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
      -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
      -DCMAKE_CXX_STANDARD=11 \
      ../..
$ make -j 
$ make install
$ popd