C++ OpenCV使用C+;在iOS上使用base64通过HTTP发送图像+;
我正在iOS上创建一个应用程序,在那里我发送一个关键点列表(这是有效的)和一个由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
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];