Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV使用C+;在iOS上使用base64通过HTTP发送图像+;_C++_Ios_Post_Opencv_Base64 - Fatal编程技术网

C++ OpenCV使用C+;在iOS上使用base64通过HTTP发送图像+;

C++ OpenCV使用C+;在iOS上使用base64通过HTTP发送图像+;,c++,ios,post,opencv,base64,C++,Ios,Post,Opencv,Base64,我正在iOS上创建一个应用程序,在那里我发送一个关键点列表(这是有效的)和一个由orbscriptorextractor生成的Mat图像。图像的发送工作正常,接收的base64与发送的base64相同。所以我猜它在编码和解码上出错了 左侧的图像在编码之前,右侧的图像是在服务器上接收的解码图像: 这是使用base64对Mat(desc)图像进行编码的代码,我使用的base64函数来自 如何以正确的方式发送OpenCV图像而不丢失数据?我使用的方法略有不同。我会写的,希望对你有所帮助: //Co

我正在iOS上创建一个应用程序,在那里我发送一个关键点列表(这是有效的)和一个由
orbscriptorextractor
生成的
Mat
图像。图像的发送工作正常,接收的base64与发送的base64相同。所以我猜它在编码和解码上出错了

左侧的图像在编码之前,右侧的图像是在服务器上接收的解码图像:

这是使用base64对
Mat
(desc)图像进行编码的代码,我使用的base64函数来自


如何以正确的方式发送OpenCV图像而不丢失数据?

我使用的方法略有不同。我会写的,希望对你有所帮助:

//Consider we have the image saved in UIImage
UIImage * myImage;

//Get the data 
NSData imageData = UIImageJPEGRepresentation(myImage, 1.0);

//I am using this extension to encode to base 64 (https://gist.github.com/Abizern/1643491)
//Article from the save author http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
NSString *encodedImage = [imageData base64EncodedString];

我将
encodedImage
发送到服务器。

您不得使用任何str。。。二进制数据上的函数

strlen((char*)inBuffer)在第一个零位停止,给出了错误的结果


使用desc.total()代替缓冲区长度

,但当它转换为JPEG时,它会被压缩。因为它是在计算函数中使用的,我担心它会导致错误。非常感谢您的工作!你能解释一下为什么我不能对二进制数据使用str函数吗?strlen遍历数组,直到找到第一个0。这对于字符串来说很好,但是对于二进制信息来说很愚蠢,比如图像,0是一个完全合法的黑色像素。看看你的照片,里面有很多这样的东西。strcat,strcpy,不管他们都有同样的问题
int processData(string input, int* width, int* height){
    int cur = 0, k = 0;
    for(unsigned int i = 0; i < input.length(); i++){
        if(input.substr(i, 2) == "^^"){
            if(cur == 0){
                k = i + 2;          
            }else if(cur == 1){
                *width = getIntFromString(input, k, i);         
                k = i + 2;
            }else{
                *height = getIntFromString(input, k, i);        
                break;
            }
            cur++;
        }
    }
    return 0;
}

int error, w, h;
string line, data;
ifstream file;

file.open(argv[1]);

if(file.is_open()){
    error = processData(line, &w, &h);
    if(error != 0){
        printf("Processing keypoints failed \n");
        return 1;
    } 
    getline(file, line);
    data = base64_decode(line);

    file.close();
}else{
    printf("Couldn't open file.\n");
    return 1;
}

Mat tex_des(Size(w, h), CV_8UC1, (void*)data.c_str());
//Consider we have the image saved in UIImage
UIImage * myImage;

//Get the data 
NSData imageData = UIImageJPEGRepresentation(myImage, 1.0);

//I am using this extension to encode to base 64 (https://gist.github.com/Abizern/1643491)
//Article from the save author http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
NSString *encodedImage = [imageData base64EncodedString];