{"id":1998,"date":"2019-06-06T16:25:09","date_gmt":"2019-06-06T13:25:09","guid":{"rendered":"https:\/\/imagga.com\/blog\/?p=1998"},"modified":"2019-06-06T16:23:55","modified_gmt":"2019-06-06T13:23:55","slug":"using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities","status":"publish","type":"post","link":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/","title":{"rendered":"Recognizing Objects in House Interior and Recommending Products with Image Recognition"},"content":{"rendered":"<div class=\"wpb-content-wrapper\">\r\n<p>[vc_row][vc_column width=&#8221;2\/3&#8243;][vc_column_text]<br \/>There is a saying that If you want to become an expert of a field, you have to be a master of classification. Photographers can tell if their latest picture was beautiful or not. Musicians can classify what sounds great. Good developers can smell a good code snippet and a bad one.<\/p>\r\n<p>Categorizations can take many hours of training for humans. Luckily, in the age of machine learning, the machines can help and save a ton of labor time for us. Today, we are going to got our feet wet by creating a photo categorizer app from scratch.<\/p>\r\n<p>The mobile app we\u2019re building is a demo. You can use it as a foundation for more complex photo organization application or as functionality within another specific application. It will take one image selected by the user, upload to Imagga APIs and categorize it. This is the final result:<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n<center><img src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/screen_move.gif\" width=\"500\" \/>\u00a0<\/center>\r\n<p>&nbsp;<\/p>\r\n<h3>Source Code<\/h3>\r\n<p>If you are looking into the code directly, feel free to skip reading and download from the side bar on right side. To get the code running, you will need to sign up with an Imagga <a href=\"https:\/\/imagga.com\/auth\/signup\">Hacker Plan<\/a>\u00a0(free), get the authorization header and replace \u2018YOUR_AUTHORIZATION_HEADER\u2019 in the code. In ViewController.swift, change \u2018authorizationHeader\u2019 constant to the value of your own key. The key looks like: \u201cBasic xxxx\u201d as in the red square below:<\/p>\r\n<p><img src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2019\/01\/imagga_api_usage_without.jpg\" \/><\/p>\r\n<h3>The Imagga API<\/h3>\r\n<p>To start, let\u2019s test our Imagga account by using this curl request from command line. This way, we can make sure that our setup is ready for the app.<a href=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2019\/01\/entrywayheroscaled.jpg\"> Here is the test image.<\/a><\/p>\r\n<pre><code class=\"code-multiline\">'curl --request GET \\\r\n--url 'https:\/\/api.imagga.com\/v2\/categories\/personal_photos?image_url=https%3A%2F%2Fimagga.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F01%2Fentrywayheroscaled.jpg' \\\r\n--header 'accept: application\/json' \\\r\n--header 'authorization:YOUR_AUTHORIZATION_HEADER''<\/code><\/pre>\r\n<p>After running the code above, we should got the result like this:<\/p>\r\n<pre><code>{\"result\":{\"categories\":[{\"confidence\":99.9999542236328,\"name\":{\"en\":\"interior objects\"}}]},\"status\":{\"text\":\"\",\"type\":\"success\"}}\r\n<\/code><\/pre>\r\n<p>Now, we confirmed that the API key works for us. Notice in the above example, we used an URL of the image file. However, the app we are going to build will use an Image file instead of an image URL. So let\u2019s see what the API doc has to say about that.<\/p>\r\n<p>Navigate to the developer\u2019s page, API Endpoints section and categories subsection: <a href=\"https:\/\/docs.imagga.com\/#categories-categorizer_id\">Imagga REST API Documentation<\/a>. We can see it asks us to send a post request to this end point, and the parameter is \u201cimage\u201d and with image file content. Be sure to keep this in mind because we gonna use it later. It\u2019s time to code!<\/p>\r\n<p>&nbsp;<\/p>\r\n<center><img src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/query_parameters.png\" \/><\/center>\r\n<p>&nbsp;<\/p>\r\n<h3>iOS Project Setup<\/h3>\r\n<p>Create a Xcode project, give it a name \u2018Imagga\u2019, select \u2018Single View App\u2019 and choose Swift as the language. In order to make the process faster, we are going to use two libraries: \u2018Alamofire\u2019 and \u2018SwiftyJSON\u2019. Make sure you have a podfile, set the platform to iOS12 and have the pods like this:<\/p>\r\n<pre><code class=\"code-multiline\"># Pods for Imagga\r\npod 'Alamofire', '~&gt; 4.8'\r\npod 'SwiftyJSON', '~&gt; 4.0'<\/code><\/pre>\r\n<p>We are going to use \u2018Alamofire\u2019 for uploading and \u2019SwiftyJSON\u2019 for parsing the json responses. To manage the libraries, we use cocoapods. Make sure you have installed both pods before moving to the next section.<\/p>\r\n<h3>A Simple Upload in Swift<\/h3>\r\n<p>First thing first: Upload image to our API. Open \u2018ViewController.swift\u2019 and add the following below<\/p>\r\n<pre><code class=\"code-multiline\">import SwiftyJSON\r\nimport Alamofire<\/code><\/pre>\r\n<p>This will let you use the Alamofire module in your code. Next, create a function \u2018sendImageToServer(image: UIImage)\u2019 and add the following to it:<\/p>\r\n<pre><code>func sendImageToServer(image: UIImage) {\r\n    guard let imageData = image.jpegData(compressionQuality: 0.5) else {\r\n        print(\"no image data find\")\r\n        return\r\n    }\r\n    \r\n    upload(multipartFormData: { (multipartFormData) in\r\n        multipartFormData.append(imageData,\r\n                                 withName: \"image\",\r\n                                 fileName: \"image.jpg\",\r\n                                 mimeType: \"image\/jpeg\")\r\n    },\r\n           to: \"https:\/\/api.imagga.com\/v2\/categories\/personal_photos\",\r\n           headers: [\"Authorization\": authorizationHeader,\r\n                     \"accept\": \"application\/json\"],\r\n           encodingCompletion: {encodingResult in\r\n            switch encodingResult {\r\n            case .success(let upload, _, _):\r\n                upload.responseJSON { response in\r\n                    debugPrint(response)\r\n                }\r\n            case .failure(let encodingError):\r\n                print(encodingError)\r\n            }})\r\n}\r\n<\/code><\/pre>\r\n<ol start=\"1\">\r\n<li>First, reduced the compress quality of the image to 0.5, so the file size will be smaller when we upload it to server.<\/li>\r\n<li>Upload an image named \u201cimage.jpg\u201d and with a parameter name \u2018image\u2019 \u2014\u2014 this is very import. If you recall from the Imagga API section, in order to upload a file, the parameter name we have to use is \u201cimage\u201d.<\/li>\r\n<li>Send the file to end point: <a href=\"https:\/\/api.imagga.com\/v2\/categories\/personal_photos\">https:\/\/api.imagga.com\/v2\/categories\/personal_photos<\/a>, make sure the authorizationHeader is setup correctly in the headers.<\/li>\r\n<li>Print the responses.<\/li>\r\n<\/ol>\r\n<p>In order to test this upload function, let\u2019s grab an image file from the project. <a href=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2019\/01\/entrywayheroscaled.jpg\">You can download it here<\/a> and add it to your Xcode project. After it\u2019s added, let\u2019s do a test to make sure our upload function works. Add the following into \u2018viewDidLoad()\u2019:<\/p>\r\n<pre><code class=\"code-multiline\"><code>override func viewDidLoad() {\r\n    super.viewDidLoad()\r\n    \/\/ Do any additional setup after loading the view, typically from a nib.\r\n    \r\n    guard let image = UIImage(named: \"entrywayheroscaled.jpg\") else {\r\n        print(\"no image found\")\r\n        return\r\n    }\r\n    sendImageToServer(image: image)\r\n}\r\n<\/code><\/code><\/pre>\r\n<p>and we should see this response from the server<\/p>\r\n<pre><code class=\"code-multiline\"><code>[Result]: SUCCESS: {\r\n    result =     {\r\n        categories =         (\r\n                        {\r\n                confidence = \"99.9999542236328\";\r\n                name =                 {\r\n                    en = \"interior objects\";\r\n                };\r\n            }\r\n        );\r\n    };\r\n    status =     {\r\n        text = \"\";\r\n        type = success;\r\n    };\r\n}\r\n<\/code><\/code><\/pre>\r\n<p>In <a href=\"http:\/\/Raywenderlich.com\">Raywenderlich.com<\/a>, there\u2019s a more detailed tutorial of how to use Alamofire, SwiftyJSON with Imagga API here: <a href=\"https:\/\/www.raywenderlich.com\/35-alamofire-tutorial-getting-started\">https:\/\/www.raywenderlich.com\/35-alamofire-tutorial-getting-started<\/a>. Since we\u2019re more focused on using the API, I\u2019ll leave the Swift side\u2014digging to you:)<\/p>\r\n<h3>Handle Return Value<\/h3>\r\n<p>The next step after we have printed the response is to handle it and save it to our data module. Add the following function to ViewController.swift<\/p>\r\n<pre><code>func handleResponse(response: DataResponse&lt;Any&gt;) {\r\n    guard response.result.isSuccess,\r\n        let value = response.result.value else {\r\n            print(\"Error while uploading file: \\(String(describing: response.result.error))\")\r\n            return\r\n    }\r\n    \r\n    self.personalPhotos = (JSON(value)[\"result\"][\"categories\"].array?.map { json in\r\n        PersonalPhoto(name: json[\"name\"][\"en\"].stringValue,\r\n                      confidence: json[\"confidence\"].doubleValue)\r\n        })!\r\n    \r\n}\r\n<\/code><\/pre>\r\n<p>and in \u2018sendImageToServer(image: UIImage)\u2019 function, add<\/p>\r\n<p><code class=\"code-inline\">self.handleResponse(response: response)<\/code><\/p>\r\n<p>after \u2018debugPrint(response)\u2019.<\/p>\r\n<p>Inside the ViewController class, add<\/p>\r\n<p><code class=\"code-inline\">var personalPhotos: [PersonalPhoto] = []<\/code><\/p>\r\n<p>before \u2018viewDidLoad()\u2019 function.<\/p>\r\n<p>Here\u2019s a step-by-step explanation of the code above:<\/p>\r\n<ol start=\"1\">\r\n<li>Check that the response was successful. If not, print the error.<\/li>\r\n<li>Use \u2018SwiftyJSON\u2019 to retrieve the \u2018categories\u2019 array from the response. It iterates through each of the categories and transforms it to a PersonalPhoto struct.<\/li>\r\n<li>Save the array into \u2018self.personalPhotos\u2019.<\/li>\r\n<li>Put it inside a call back block after sending the image.<\/li>\r\n<li>Add a variable in ViewController to save the categories.<\/li>\r\n<\/ol>\r\n<p>We don\u2019t have a PersonalPhoto struct yet, so let\u2019s create one. Create a new file named: PersonalPhoto.swift. Add the following to it:<\/p>\r\n<pre><code>struct PersonalPhoto {\r\n    var name: String\r\n    var confidence: Double\r\n}\r\n<\/code><\/pre>\r\n<p>Run the project, and set a breakpoint right after we assigned value to self.personalPhotos. We should see one PersonalPhoto object in the array.<\/p>\r\n<p><img src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/sucess.png\" \/><\/p>\r\n<p>That means we are good for upload image and parse the responses. Now it is time to show the results in UI.<\/p>\r\n<h3>Connect UI in Xcode<\/h3>\r\n<p>Let\u2019s see our app UI in the Main.storyboard file.<\/p>\r\n<p><img src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/interior_objects.png\" \/><\/p>\r\n<p>There are three main items: 1. Image view, 2 Table view 3. Select button.<\/p>\r\n<p>Here are my constrains:<\/p>\r\n<ul>\r\n<li>Image view: Height 200, leading &amp; trailing space 10, top space 20, horizontal center. Default image: \u2018entrywayheroscaled.jpg\u2019, set contentMode to \u2018Aspect Fit\u2019<\/li>\r\n<li>Select button: Height 50, Width 100, horizontal center, top to Image View 20<\/li>\r\n<li>Table view: Height 200, leading &amp; trailing space 10, top to Select button 20<\/li>\r\n<\/ul>\r\n<p>Drag a prototype UITableViewCell into the tableview, and give it a container view, a confidence label on the left and a name label on the right. Tweak the label size, color and position as you would like. Make sure you connect the IBOutlets into ViewController.<\/p>\r\n<pre><code class=\"code-multiline\">@IBOutlet weak var imageView: UIImageView!\r\n@IBOutlet weak var tableView: UITableView!<\/code><\/pre>\r\n<p><strong>Now our UI is good to go.<\/strong><\/p>\r\n<h3>Select Photo from User Library<\/h3>\r\n<p>Since we are going to select the photo from user\u2019s photo library, we connect \u2018Select Button\u2019 IBAction event into a buttonPressed function:<\/p>\r\n<pre><code>@IBAction func buttonPressed(_ sender: Any) {\r\n    openPhotoLibraray()\r\n}\r\n<\/code><\/pre>\r\n<p>and call \u2018openPhotoLibraray()\u2019 function inside it.<\/p>\r\n<p>In order to open the system photo library, add \u2018UIImagePickerControllerDelegate\u2019 and \u2018UINavigationControllerDelegate\u2019 to the ViewController class.<\/p>\r\n<pre><code class=\"code-multiline\">class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITableViewDataSource {<\/code><\/pre>\r\n<p>The calling system photo library part is straight forward:<\/p>\r\n<pre><code>func openPhotoLibraray() {\r\n    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {\r\n        let picker = UIImagePickerController()\r\n        picker.delegate = self as UIImagePickerControllerDelegate &amp; UINavigationControllerDelegate\r\n        picker.sourceType = .photoLibrary\r\n        self.present(picker, animated: true) {\r\n            \r\n        }\r\n    }\r\n}\r\n\r\nfunc imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {\r\n    picker.dismiss(animated: true)\r\n    \r\n    guard let image = info[.originalImage] as? UIImage else {\r\n        print(\"No image found\")\r\n        return\r\n    }\r\n    \r\n    imageView.image = image\r\n}\r\n<\/code><\/pre>\r\n<p>Now if you build and run the project, \u201cSelect Photo\u201d button will give you the build-in photo library and you can choose a photo. The Image View will display the photo you selected.<\/p>\r\n<h2>Connect Two Parts Together<\/h2>\r\n<p>We now have two parts:<\/p>\r\n<ol start=\"1\">\r\n<li>Upload an image to server and handle the responses.<\/li>\r\n<li>Select an image from the user photos library.<\/li>\r\n<\/ol>\r\n<p>Let\u2019s remove all the testing code inside \u2018viewDidLoad()\u2019, and in the last line of<\/p>\r\n<p><code class=\"code-inline\">func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])<\/code><\/p>\r\n<p>add \u2018sendImageToServer(image: image)\u2019 right after \u2018imageView.image = image\u2019. Build and run the project, select a photo from your library, and you should see the responses in the logs.<\/p>\r\n<h3>UI Tweaks<\/h3>\r\n<p>It is time to display the responses in UI. We are going to show the result like below:<\/p>\r\n<p>&nbsp;<\/p>\r\n<center><img src=\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/macro_flowers.png\" \/><\/center>\r\n<p>It is a tableview with multiple cells. In each cell, we display the categorizer\u2019s name, confidence and the color indicator in the background.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>To get the tableViewCell to work, create a subclass of UITableViewCell and name it \u2018PersonalPhotoCell\u2019 and connect all three IBOutlets<\/p>\r\n<pre><code>class PersonalPhotoCell: UITableViewCell {\r\n    @IBOutlet weak var nameLabel: UILabel!\r\n    @IBOutlet weak var confidenceLabel: UILabel!\r\n    @IBOutlet weak var containerView: ConfidenceView!\r\n    \r\n<\/code><\/pre>\r\n<p>and ConfidenceView.swift as follow:<\/p>\r\n<pre><code>import UIKit\r\n@IBDesignable\r\nclass ConfidenceView: UIView {\r\n    @IBInspectable var confidence: Double = 0 {\r\n        didSet {\r\n            setNeedsDisplay()\r\n        }\r\n    }\r\n    \r\n    override func draw(_ rect: CGRect) {\r\n        \/\/ Drawing code\r\n        let color = UIColor.init(red: 123.0\/255.0, green: 184.0\/255.0, blue: 183.0\/255.0, alpha: 1.0)\r\n        \r\n        let rectToDraw = CGRect(x: 0, y: 0, width: CGFloat(rect.size.width) * CGFloat(confidence), height: rect.size.height)\r\n        let path : UIBezierPath = UIBezierPath(rect: rectToDraw)\r\n        color.set()\r\n        path.fill()\r\n    }\r\n}\r\n<\/code><\/pre>\r\n<p>The ConfidenceView.swift is a subclass of UIView, and we use it as a container. The view only draw the percentage of confidence with color. This way it gives a good visual impression of the confidence level. In the tableView delegate:<\/p>\r\n<pre><code>func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {\r\n    return personalPhotos.count\r\n}\r\n\r\nfunc tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {\r\n    let cell = tableView.dequeueReusableCell(withIdentifier: \"Cell\", for: indexPath) as! PersonalPhotoCell\r\n    let personalPhoto = personalPhotos[indexPath.row] as PersonalPhoto\r\n    cell.nameLabel.text = personalPhoto.name\r\n    cell.confidenceLabel.text = String(format: \"%.2f%%\", personalPhoto.confidence)\r\n    cell.containerView.confidence = personalPhoto.confidence \/ 100.0\r\n    return cell\r\n}\r\n<\/code><\/pre>\r\n<p>We use our variable personalPhotos as the data source and set it accordingly to display in the cell. Notice those two lines:<\/p>\r\n<pre><code class=\"code-multiline\">cell.confidenceLabel.text = String(format: \"%.2f%%\", personalPhoto.confidence)\r\ncell.containerView.confidence = personalPhoto.confidence \/ 100.0<\/code><\/pre>\r\n<p>We want to format it with two decimal points and also control the confidence value between 0 ~ 1 for the confidenceView.<\/p>\r\n<p><strong>Now if you run the project and select a photo, nothing is going to happen. But why?<\/strong><\/p>\r\n<p>This is because we haven\u2019t updated our tableview after receiving the responses, so let\u2019s do that now. In the upload image function, add<\/p>\r\n<p><code class=\"code-inline\">self.tableView.reloadData()<\/code><\/p>\r\n<p>right after \u2018self.handleResponse(response: response)\u2019, this way we\u2019re going to have an updated tableview once handled all the responses.<\/p>\r\n<p><strong>Run the project, select a photo you like and the server gonna return a categorizer it fits. And now, we\u2019re good! <\/strong><\/p>\r\n<h2>Best API Practice<\/h2>\r\n<p>Before we wrap up our tutorial, I want to emphasize on the best practices of the API: <a href=\"https:\/\/docs.imagga.com\/#best-practices\">Imagga REST API Documentation<\/a>For the image size:<\/p>\r\n<pre><code class=\"code-inline\">The API doesn't need more that 300px on the shortest side to provide you with the same great results<\/code><\/pre>\r\n<p>And for a good confidence level:<\/p>\r\n<pre><code class=\"code-inline\">Our suggestion is setting the confidence threshold at 15-20%.<\/code><\/pre>\r\n<p>So with those two points in mind, if you want to make the upload faster while keep the same quality, crop the image\u2019s shortest side to 300px. Also, by filtering out all the categories with a confidence less than 80%, you will get a more accurate result.<\/p>\r\n<h3>Conclusion<\/h3>\r\n<p>Today we\u2019ve gone through how to use the categorization API and create the iOS app from scratch by using Swift. Hope you enjoy the reading and had fun . Feel free to leave any questions and keep me updated on what you going to build next. Cheers!<\/p>\r\n<h2>References<\/h2>\r\n<p><a href=\"https:\/\/docs.imagga.com\/\">Imagga REST API Documentation<\/a><\/p>\r\n<p><a href=\"https:\/\/imagga.com\/solutions\/categorization-api.html\">Categorization API for Image Classification | Imagga Solutions<\/a><\/p>\r\n<p><a href=\"https:\/\/www.raywenderlich.com\/35-alamofire-tutorial-getting-started\">Alamofire Tutorial: Getting Started | raywenderlich.com<\/a><\/p>\r\n<p><a href=\"https:\/\/imagga.com\/blog\/autotagging-uploads-with-nodejs\/\">Create Autotagging Uploads with NodeJS using Image Recognition API &#8211; Imagga Blog<\/a><\/p>\r\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=cAICT4Al5Ow\">How to Make an Image Classifier &#8211; Intro to Deep Learning #6 &#8211; YouTube<\/a><\/p>\r\n<p>[\/vc_column_text][\/vc_column]<br \/>[vc_column width=&#8221;1\/3&#8243;][vc_column_text]<\/p>\r\n<p><!-- Begin Mailchimp Signup Form --><\/p>\r\n<p><style type=\"text\/css\">\r\n#mc-embedded-subscribe-form input[type=checkbox]{display: inline; width: auto;margin-right: 10px;}<br \/>#mergeRow-gdpr {margin-top: 20px;}<br \/>#mergeRow-gdpr fieldset label {font-weight: normal;}<br \/>#mc-embedded-subscribe-form .mc_fieldset{border:none;min-height: 0px;padding-bottom:0px;}<br \/><\/style><\/p>\r\n<div id=\"mc_embed_signup\" style=\"background-color: #e7e7e7; clear: left; font: 14px Helvetica,Arial,sans-serif; border: 1px solid #ccc; padding: 0 1rem 1rem;\"><form id=\"mc-embedded-subscribe-form\" class=\"validate\" action=\"https:\/\/imagga.us2.list-manage.com\/subscribe\/post?u=b1ac9881f9fa5cda50097f7a1&amp;id=94ca40bce9\" method=\"post\" name=\"mc-embedded-subscribe-form\" novalidate=\"\" target=\"_blank\">\r\n<div id=\"mc_embed_signup_scroll\">\r\n<h5 style=\"margin: 1rem 0; color: #000;\">Free iOS App with Image Recognition<\/h5>\r\n<div class=\"mc-field-group\"><label style=\"font-size: 0.9rem; color: #05193c;\" for=\"mce-FNAME\">First Name <\/label><br \/><input id=\"mce-FNAME\" class=\"\" style=\"width: 90%; margin: 0 0 1rem 0;\" name=\"FNAME\" type=\"text\" value=\"\" \/><\/div>\r\n<div class=\"mc-field-group\"><label style=\"font-size: 0.9rem; color: #05193c;\" for=\"mce-LNAME\">Last Name <\/label><br \/><input id=\"mce-LNAME\" class=\"\" style=\"width: 90%; margin: 0 0 1rem 0;\" name=\"LNAME\" type=\"text\" value=\"\" \/><\/div>\r\n<div class=\"mc-field-group\"><label style=\"font-size: 0.9rem; color: #05193c;\" for=\"mce-EMAIL\">Email Address <span style=\"color: red;\">*<\/span> <\/label><input id=\"mce-EMAIL\" class=\"required email\" style=\"width: 90%; margin: 0 0 1rem 0;\" name=\"EMAIL\" type=\"email\" value=\"\" \/><\/div>\r\n<div id=\"mergeRow-gdpr\" class=\"mergeRow gdpr-mergeRow content__gdprBlock mc-field-group\">\r\n<div class=\"content__gdpr\">\r\n<h5 style=\"font-size: 0.9rem; color: #000;\">Marketing Permissions For Imagga<\/h5>\r\n<fieldset class=\"mc_fieldset gdprRequired mc-field-group\" style=\"margin-bottom: 1rem; border: none;\" name=\"interestgroup_field\"><label class=\"checkbox subfield\" for=\"gdpr_5289\"><input id=\"gdpr_5289\" class=\"av-checkbox \" style=\"height: 18px; display: inline-block;\" name=\"gdpr[5289]\" type=\"checkbox\" value=\"Y\" \/><span style=\"font-size: 0.9rem; color: #05193c;\">Email<\/span> <\/label><br \/><label class=\"checkbox subfield\" for=\"gdpr_5293\"><input id=\"gdpr_5293\" class=\"av-checkbox \" style=\"height: 18px; display: inline-block;\" name=\"gdpr[5293]\" type=\"checkbox\" value=\"Y\" \/><span style=\"font-size: 0.9rem; color: #05193c;\">Direct Mail<\/span> <\/label><br \/><label class=\"checkbox subfield\" for=\"gdpr_5297\"><input id=\"gdpr_5297\" class=\"av-checkbox \" style=\"height: 18px; display: inline-block;\" name=\"gdpr[5297]\" type=\"checkbox\" value=\"Y\" \/><span style=\"font-size: 0.9rem; color: #05193c;\">Customized Online Advertising<\/span> <\/label><\/fieldset>\r\n<p style=\"font-size: 0.7rem; font-weight: 400; margin: 0 0 0.6rem 0; color: #747980;\">We are always concious about sending a lot of emails, so our commitment is that we will send only when there is something interesting or free knowledge that we would like to share with you. If you feel like we are not living up to that expectation you can unsubscribe at any time by clicking the link in the footer of our emails.<\/p>\r\n<\/div>\r\n<\/div>\r\n<div id=\"mce-responses\" class=\"clear\">\r\n<div id=\"mce-error-response\" class=\"response\" style=\"display: none;\">\u00a0<\/div>\r\n<div id=\"mce-success-response\" class=\"response\" style=\"display: none;\">\u00a0<\/div>\r\n<\/div>\r\n<p><!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--><\/p>\r\n<div style=\"position: absolute; left: -5000px;\" aria-hidden=\"true\"><input tabindex=\"-1\" name=\"b_b1ac9881f9fa5cda50097f7a1_94ca40bce9\" type=\"text\" value=\"\" \/><\/div>\r\n<div class=\"clear\"><input id=\"mc-embedded-subscribe\" class=\"button\" style=\"background-color: #2c3945; color: #fff;\" name=\"subscribe\" type=\"submit\" value=\"Download Code File\" \/><\/div>\r\n<\/div>\r\n<\/form><\/div>\r\n<p><script type=\"text\/javascript\" src=\"\/\/s3.amazonaws.com\/downloads.mailchimp.com\/js\/mc-validate.js\"><\/script><script type=\"text\/javascript\">(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';fnames[3]='ADDRESS';ftypes[3]='address';fnames[4]='PHONE';ftypes[4]='phone';}(jQuery));var $mcj = jQuery.noConflict(true);<\/script><br \/><!--End mc_embed_signup--><\/p>\r\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\r\n<p><\/p><\/div>","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column width=&#8221;2\/3&#8243;][vc_column_text]There is a saying that If you want to become an expert of a field, you have to be [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":1997,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,211],"tags":[31,143,170,208,209,210],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Recognizing Objects in House Interior and Recommending Products with Image Recognition - Imagga Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Recognizing Objects in House Interior and Recommending Products with Image Recognition - Imagga Blog\" \/>\n<meta property=\"og:description\" content=\"[vc_row][vc_column width=&#8221;2\/3&#8243;][vc_column_text]There is a saying that If you want to become an expert of a field, you have to be [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/\" \/>\n<meta property=\"og:site_name\" content=\"Imagga Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/imagga\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-06T13:25:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-06T13:23:55+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@imagga\" \/>\n<meta name=\"twitter:site\" content=\"@imagga\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Le Zeng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/imagga.com\/blog\/#organization\",\"name\":\"Imagga\",\"url\":\"https:\/\/imagga.com\/blog\/\",\"sameAs\":[\"https:\/\/www.facebook.com\/imagga\/\",\"https:\/\/twitter.com\/imagga\",\"https:\/\/www.linkedin.com\/company\/imagga\/\",\"https:\/\/twitter.com\/imagga\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imagga.com\/blog\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg\",\"contentUrl\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg\",\"width\":\"27\",\"height\":\"29\",\"caption\":\"Imagga\"},\"image\":{\"@id\":\"https:\/\/imagga.com\/blog\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/imagga.com\/blog\/#website\",\"url\":\"https:\/\/imagga.com\/blog\/\",\"name\":\"Imagga Blog\",\"description\":\"Image recognition in the cloud\",\"publisher\":{\"@id\":\"https:\/\/imagga.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/imagga.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg\",\"contentUrl\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#webpage\",\"url\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/\",\"name\":\"Recognizing Objects in House Interior and Recommending Products with Image Recognition - Imagga Blog\",\"isPartOf\":{\"@id\":\"https:\/\/imagga.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#primaryimage\"},\"datePublished\":\"2019-06-06T13:25:09+00:00\",\"dateModified\":\"2019-06-06T13:23:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/imagga.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Recognizing Objects in House Interior and Recommending Products with Image Recognition\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#webpage\"},\"author\":{\"@id\":\"https:\/\/imagga.com\/blog\/#\/schema\/person\/a684a6a63f3e2b884389dff92486b86c\"},\"headline\":\"Recognizing Objects in House Interior and Recommending Products with Image Recognition\",\"datePublished\":\"2019-06-06T13:25:09+00:00\",\"dateModified\":\"2019-06-06T13:23:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#webpage\"},\"wordCount\":1723,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/imagga.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg\",\"keywords\":[\"image processing\",\"application\",\"json\",\"Swifty\",\"app\",\"photography\"],\"articleSection\":[\"Trending\",\"Code Hacks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/imagga.com\/blog\/#\/schema\/person\/a684a6a63f3e2b884389dff92486b86c\",\"name\":\"Le Zeng\",\"sameAs\":[\"http:\/\/zenglekidd@gmail.com\"],\"url\":\"https:\/\/imagga.com\/blog\/author\/lezeng\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Recognizing Objects in House Interior and Recommending Products with Image Recognition - Imagga Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/","og_locale":"en_US","og_type":"article","og_title":"Recognizing Objects in House Interior and Recommending Products with Image Recognition - Imagga Blog","og_description":"[vc_row][vc_column width=&#8221;2\/3&#8243;][vc_column_text]There is a saying that If you want to become an expert of a field, you have to be [&hellip;]","og_url":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/","og_site_name":"Imagga Blog","article_publisher":"https:\/\/www.facebook.com\/imagga\/","article_published_time":"2019-06-06T13:25:09+00:00","article_modified_time":"2019-06-06T13:23:55+00:00","og_image":[{"width":1920,"height":1080,"url":"http:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg","type":"image\/jpeg"}],"twitter_card":"summary","twitter_creator":"@imagga","twitter_site":"@imagga","twitter_misc":{"Written by":"Le Zeng","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/imagga.com\/blog\/#organization","name":"Imagga","url":"https:\/\/imagga.com\/blog\/","sameAs":["https:\/\/www.facebook.com\/imagga\/","https:\/\/twitter.com\/imagga","https:\/\/www.linkedin.com\/company\/imagga\/","https:\/\/twitter.com\/imagga"],"logo":{"@type":"ImageObject","@id":"https:\/\/imagga.com\/blog\/#logo","inLanguage":"en-US","url":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg","contentUrl":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/logo_white_blog.svg","width":"27","height":"29","caption":"Imagga"},"image":{"@id":"https:\/\/imagga.com\/blog\/#logo"}},{"@type":"WebSite","@id":"https:\/\/imagga.com\/blog\/#website","url":"https:\/\/imagga.com\/blog\/","name":"Imagga Blog","description":"Image recognition in the cloud","publisher":{"@id":"https:\/\/imagga.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imagga.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#primaryimage","inLanguage":"en-US","url":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg","contentUrl":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg","width":1920,"height":1080},{"@type":"WebPage","@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#webpage","url":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/","name":"Recognizing Objects in House Interior and Recommending Products with Image Recognition - Imagga Blog","isPartOf":{"@id":"https:\/\/imagga.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#primaryimage"},"datePublished":"2019-06-06T13:25:09+00:00","dateModified":"2019-06-06T13:23:55+00:00","breadcrumb":{"@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/imagga.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Recognizing Objects in House Interior and Recommending Products with Image Recognition"}]},{"@type":"Article","@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#article","isPartOf":{"@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#webpage"},"author":{"@id":"https:\/\/imagga.com\/blog\/#\/schema\/person\/a684a6a63f3e2b884389dff92486b86c"},"headline":"Recognizing Objects in House Interior and Recommending Products with Image Recognition","datePublished":"2019-06-06T13:25:09+00:00","dateModified":"2019-06-06T13:23:55+00:00","mainEntityOfPage":{"@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#webpage"},"wordCount":1723,"commentCount":0,"publisher":{"@id":"https:\/\/imagga.com\/blog\/#organization"},"image":{"@id":"https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#primaryimage"},"thumbnailUrl":"https:\/\/imagga.com\/blog\/wp-content\/uploads\/2017\/04\/alomfire_swifjson.jpg","keywords":["image processing","application","json","Swifty","app","photography"],"articleSection":["Trending","Code Hacks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/imagga.com\/blog\/using-alomfire-and-swiftyjson-to-create-an-app-with-image-recognition-capabilities\/#respond"]}]},{"@type":"Person","@id":"https:\/\/imagga.com\/blog\/#\/schema\/person\/a684a6a63f3e2b884389dff92486b86c","name":"Le Zeng","sameAs":["http:\/\/zenglekidd@gmail.com"],"url":"https:\/\/imagga.com\/blog\/author\/lezeng\/"}]}},"_links":{"self":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts\/1998"}],"collection":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/comments?post=1998"}],"version-history":[{"count":85,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts\/1998\/revisions"}],"predecessor-version":[{"id":3224,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/posts\/1998\/revisions\/3224"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/media\/1997"}],"wp:attachment":[{"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/media?parent=1998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/categories?post=1998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imagga.com\/blog\/wp-json\/wp\/v2\/tags?post=1998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}