convert

how to convert from cvMat to UIImage in objective-c?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using the OpenCV framework with XCode and want to convert from cvMat or IplImage to UIImage, how to do that? Thanks. 回答1: Note: most implementations don't correctly handle an alpha channel or convert from OpenCV's BGR pixel format to iOS's RGB. This will correctly convert from cv::Mat to UIImage : +(UIImage *)UIImageFromCVMat:(cv::Mat)cvMat { NSData *data = [NSData dataWithBytes:cvMat.data length:image.step.p[0]*image.rows]; CGColorSpaceRef colorSpace; CGBitmapInfo bitmapInfo; if (cvMat.elemSize() == 1) { colorSpace =

Convert javascript to date object to mysql date format (YYYY-MM-DD)

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use javascript to convert a date object into a valid mysql date - what is the best way to do this? 回答1: Probably best to use a library like Date.js (although that hasn't been maintained in years) or Moment.js . But to do it manually, you can use Date#getFullYear() , Date#getMonth() (it starts with 0 = January, so you probably want + 1), and Date#getDate() (day of month). Just pad out the month and day to two characters, e.g.: (function() { Date.prototype.toYMD = Date_toYMD; function Date_toYMD() { var year, month, day; year =

Convert JObject into Dictionary<string, object>. Is it possible?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a web API method that accepts an arbitrary json payload into a JObject property. As such I don't know what's coming but I still need to translate it to .NET types. I would like to have a Dictionary so that I can deal with it any way I want to. I have searched a lot, but couldn't find anything and ended up starting a messy method to do this conversion, key by key, value by value. Is there an easy way to do it? Input -> JObject person = new JObject( new JProperty("Name", "John Smith"), new JProperty("BirthDate", new DateTime(1983, 3, 20

Ruby on Rails - unable to convert “\\x89” from ASCII-8BIT to UTF-8 for xxx/xxxx/xxxx

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am installing ruby on rails 4.0.0 on my linux system , but i am getting this kind of errors unable to convert "\x89" from ASCII-8BIT to UTF8 for guides/assets/images/getting_started/routing_error_no_route_matches.png, skipping and many similar errors , i read here that it won't cause any effect ,but i do not understand why it is coming . Any pointers? 回答1: You need to update / install a version of the rdoc gem that supports the conversion. Then these errors won't appear during generation of the documentation when you install rails or when

Scala: convert map to case class

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I have this example case class case class Test(key1: Int, key2: String, key3: String) And I have a map myMap = Map("k1" -> 1, "k2" -> "val2", "k3" -> "val3") I need to convert this map to my case class in several places of the code, something like this: myMap.asInstanceOf[Test] What would be the easiest way of doing that? Can I somehow use implicit for this? 回答1: Two ways of doing this elegantly. The first is to use an unapply , the second to use an implicit class (2.10+) with a type class to do the conversion for you. 1) The

convert interface{} to int in Golang

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to Golang and I'm trying to get a value from a JSON and cast it to int but it doesn't work. Don't know how to do it properly. Here is the error message: ...cannot convert val (type interface {}) to type int: need type assertion And the Code: var f interface{} err = json.Unmarshal([]byte(jsonStr), &f) if err != nil { utility.CreateErrorResponse(w, "Error: failed to parse JSON data.") return } m := f.(map[string]interface{}) val, ok := m["area_id"] if !ok { utility.CreateErrorResponse(w, "Error: Area ID is missing from submitted data."

Convert NSURL to local file path

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an NSURL that looks like this: file://localhost/Users/myuser/myfile.txt Is there a standard function to convert it to a local file path looking like this: /Users/myuser/myfile.txt 回答1: Use the -[NSURL path] method: NSLog(@"%@", myUrl.path); From the documentation: The path of the URL, unescaped with the stringByReplacingPercentEscapesUsingEncoding: method. If the receiver does not conform to RFC 1808, returns nil . If this URL object contains a file URL (as determined with isFileURL ), the return value of this method is suitable for

How do I convert a string to a class method?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is how to convert a string to a class in Rails/Ruby: p = "Post" Kernel.const_get(p) eval(p) p.constantize But what if I am retrieving a method from an array/active record object like: Post.description but it could be Post.anything where anything is a string like anything = "description" . This is helpful since I want to refactor a very large class and reduce lines of code and repetition. How can I make it work? 回答1: Post.send(anything) 回答2: While eval can be a useful tool for this sort of thing, and those from other backgrounds may take

Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have to wait for long after using this LibreOffice command which is intended to convert DOCX into PDF: libreoffice --headless --convert-to pdf test.docx --outdir /pdf But I'm getting no response and no error. No file is converted. It looks like terminal is hanging. So, is there is any way to track the error? 回答1: I would first of all try it with giving absolute paths to the command. I suspect that the libreoffice binary does not work -- you have to locate the soffice binary and see if that works. Then, your --convert-to pdf is not

How to convert a list to a matrix more efficiently in R?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a list of length 130,000 where each element is a character vector of length 110. I would like to convert this list to a matrix with dimension 1,430,000*10. How can I do it more efficiently? My code is : output=NULL for(i in 1:length(z)) output=rbind(output,matrix(z[[i]],ncol=10,byrow=T)) 回答1: This should be equivalent to your current code, only a lot faster: output 回答2: I think you want output i.e. combining @BlueMagister's use of do.call(rbind,...) with an lapply statement to convert the individual list elements into 11*10 matrices .