我目前在Python程序中从二进制数据字符串创建图像时遇到问题.我通过套接字接收二进制数据,但是当我尝试我在这里阅读的方法时,如下所示:
buff = StringIO.StringIO() #buffer where image is stored
#Then I concatenate data by doing a
buff.write(data) #the data from the socket
im = Image.open(buff)
Run Code Online (Sandbox Code Playgroud)
我对"图像类型未识别"的效果有异常.我知道我正在接收数据,因为如果我将图像写入文件然后打开文件它会工作:
buff = StringIO.StringIO() #buffer where image is stored
buff.write(data) #data is from the socket
output = open("tmp.jpg", 'wb')
output.write(buff)
output.close()
im = Image.open("tmp.jpg")
im.show()
Run Code Online (Sandbox Code Playgroud)
我想我在使用StringIO类时可能做错了但是我不确定
目前我正在使用boost::program_options解析BeagleBoard(基于ARM的处理器)上的配置文件.我的程序是多线程的,并与boost 1.45 multithreaded库相关联.
我的程序似乎在解析配置文件时会挂起
namespace po = boost::program_options;
po::options_description desc("Options");
uint32_t option1=0;
std::vector<std::string> optionsString;
std::cout<<"Before adding options"<<std::endl;
desc.add_options()
("option1",
po::value<uint32_t>(&option1), "...")
("finaloption",
po::value<std::vector<std::string> >(&optionsString)->multitoken(), "string of options");
//Never gets here
std::cout<<"After adding options"<<std::endl;
po::variables_map vm;
std::cout<<"Starting program"<<std::endl;
Run Code Online (Sandbox Code Playgroud)
程序在打印出"添加选项后"之前挂起.如果我通过gdb运行程序停止并执行后退跟踪,它只是显示它在"永远不会到达此处"注释之前就行了.回溯的顶部就是它
#0 ??
#1 __lll_lock_wait lowlevellock.c:47
#2 __pthread_mutex_lock pthread_mutex_lock.c:61
#3 in boost::shared_ptr<boost::program_options::option_description>* std::__uninitialized_move_a<boost::shared_ptr<boost::program_options::option_description>*, boost::shared_ptr<boost::program_options::option_description>*, std::allocator<boost::shared_ptr<boost::program_option::option_description> > >(boost::shared_ptr<boost::program_optionns::option_description>*, boost::shared_ptr<boost::program_options::option_description>*, std::allocator<boost::shared_ptr<boost::program_options::option_description> >&) () from /usr/local/lib/libboost_program_options-mt.so.1.45.0
#4 in std::vector<boost::shared_ptr<boost::program_options::option_description>, std::allocator<boost::shared_ptr<boost::program_options::option_description> > >::_M_insert_aux(__gnu_cxx::__normal_iterator<boost::shared_ptr<boost::program_options::option_description>, std::vector<boost::shared_ptr<boost::program_options::option_description>, std::allocator<boost::shared_ptr<boost::program_options::option_description> const&)() from /usr/local/lib/libboost_program_options-mt.so.1.45.0
#5 in boost::program_options::options_description::add(boost::shared_ptr<boost::program_options::option_description>) () from …Run Code Online (Sandbox Code Playgroud) 在我正在写的函数中,我试图返回一个指向无符号字符向量的指针.相关代码如下.
std::vector<unsigned char> *ret = new std::vector<unsigned char>(buffSize,'0');
//Due to suggestions...
int n = recvfrom(fd_, ret, buffSize, &recvAddress, &sockSize);
//Forgot to include this in the original
ret->resize(n);
// display chars somehow just for testing
for(std::vector<unsigned char>::iterator it=ret->begin(); it<ret->end();it++)
{
std::cout<<*it;
}
std::cout<<std::endl;
...
return ret;
Run Code Online (Sandbox Code Playgroud)
当我通过valgrind运行时,我得到的错误是关于recvfrom中的缓冲区如何指向未初始化的字节.我把它缩小到向量,因为我把它换成了一个unsigned char数组,一切正常.有什么建议?
编辑1:修正了一些代码,是从内存/笔记中做到这一点,我遇到了一个问题.我开始使用valgrind的原因是我在那个地方遇到了分段错误.我会仔细检查明天我在做什么.