{"id":212,"date":"2020-07-04T15:34:04","date_gmt":"2020-07-04T07:34:04","guid":{"rendered":"http:\/\/blog.yuekegu.com\/?p=212"},"modified":"2020-07-04T15:34:04","modified_gmt":"2020-07-04T07:34:04","slug":"mathpix%e6%94%b6%e8%b4%b9%e4%ba%86%ef%bc%9f%e5%bf%ab%e4%bd%bf%e7%94%a8api%e5%90%a7%ef%bc%8c%e4%b8%aa%e6%9c%88%e5%85%8d%e8%b4%b9%e8%af%86%e5%88%ab1000%e6%ac%a1%ef%bc%81","status":"publish","type":"post","link":"https:\/\/book.yuekegu.com\/index.php\/2020\/07\/04\/mathpix%e6%94%b6%e8%b4%b9%e4%ba%86%ef%bc%9f%e5%bf%ab%e4%bd%bf%e7%94%a8api%e5%90%a7%ef%bc%8c%e4%b8%aa%e6%9c%88%e5%85%8d%e8%b4%b9%e8%af%86%e5%88%ab1000%e6%ac%a1%ef%bc%81\/","title":{"rendered":"Mathpix\u6536\u8d39\u4e86\uff1f\u5feb\u4f7f\u7528API\u5427\uff0c\u4e2a\u6708\u514d\u8d39\u8bc6\u522b1000\u6b21\uff01"},"content":{"rendered":"\n<p>\u6700\u8fd1\uff0c\u6570\u5b66\u516c\u5f0fOCR\u795e\u5668Mathpix \u5f00\u59cb\u6536\u8d39\uff0c\u4e00\u4e2a\u6708\u53ea\u80fd\u514d\u8d39\u752850\u6b21\uff0c\u518d\u7528\u5c31\u5f975\u5200\u4e00\u6708\uff0c\u5c0f\u4f19\u4f34\u4eec\u987f\u65f6\u53eb\u82e6\u4e0d\u8fed\u3002\u60f3\u60f3\u8fd9\u79cd\u5957\u8def\u56fd\u5185\u4e92\u8054\u7f51\u516c\u53f8\u4e0d\u77e5\u9053\u73a9\u4e86\u591a\u5c11\u6b21\u4e86\uff0c\u4ece\u6ef4\u6ef4\u6253\u8f66\u5230\u7f8e\u56e2\u5916\u5356\u518d\u5230\u5171\u4eab\u5355\u8f66\uff0c\u90fd\u662f\u5148\u57f9\u517b\u6d88\u8d39\u4e60\u60ef\u518d\u6536\u5272\u4e00\u6ce2\u97ed\u83dc\u3002\u4f46\u662f\u5f53\u521d\u5927\u5bb6\u90fd\u53ea\u987e\u4eab\u53d7\u514d\u8d39\u8bc6\u522b\u516c\u5f0f\u5e26\u6765\u7684\u5feb\u611f\uff0c\u54ea\u77e5\u7531\u4fed\u5165\u5962\u6613\uff0c\u7531\u5962\u5165\u4fed\u96be\uff0c\u73b0\u5728\u518d\u624b\u6572\u516c\u5f0f\u771f\u662f\u75db\u82e6\u4e0d\u582a\u3002<\/p>\n\n\n\n<p>\u76ee\u524d\u6765\u770b\uff0c\u7531\u4e8e\u9700\u8981\u8054\u7f51\u8bc6\u522b\uff0c\u57fa\u672c\u6ca1\u6709\u7a7a\u5b50\u53ef\u94bb\u3002\u5f53\u7136\u4e5f\u4e0d\u6392\u9664\u4e2a\u522b\u795e\u4eba\u7528\u5927\u91cf\u90ae\u7bb1\u6765\u767d\u5ad6\uff1a<a target=\"_blank\" href=\"https:\/\/www.zhihu.com\/question\/338462426\/answer\/793097934\" rel=\"noreferrer noopener\">\u5982\u4f55\u770b\u5f85 Mathpix \u6536\u8d39\uff1f\u200bwww.zhihu.com<\/a><\/p>\n\n\n\n<p>\u4f46\u662f\uff0cMathpix\u5b98\u7f51\u5bf9\u4e8e\u4e00\u4e9b\u6709\u80fd\u529b\u7684\u5f00\u53d1\u8005\u8fd8\u662f\u5f00\u4e86\u4e00\u6247\u540e\u95e8\u7684\uff1a<a target=\"_blank\" href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/mathpix.com\/ocr\" rel=\"noreferrer noopener\">Mathpix OCR\u200bmathpix.com<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-3ce7dfc5d9d8fb555c37a85c40a3395e_720w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4ece\u5b83\u63d0\u4f9b\u7684OCR API\u6765\u770b\uff0c\u4e00\u4e2a\u6708\u53ef\u4ee5\u514d\u8d39\u4f7f\u75281000\u6b21\uff01\u5728\u4e4b\u540e\u4e00\u76f4\u523010\u4e07\u6b21\u90fd\u662f0.004\u7f8e\u5143\uff08\u7ea6\u54080.028\u5143\uff09\u4e00\u6b21\u3002\u5bf9\u4e2a\u4eba\u4f7f\u7528\u8005\u800c\u8a00\uff0c1000\u6b21\u5df2\u7ecf\u57fa\u672c\u591f\u4e86\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u9700\u8981\u767b\u5f55\u5e73\u53f0\uff1a<a target=\"_blank\" href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/dashboard.mathpix.com\/login\" rel=\"noreferrer noopener\">MathpixOCR login\u200bdashboard.mathpix.com<\/a><\/p>\n\n\n\n<p>\u767b\u5f55\u4e4b\u540e\u9700\u8981\u8f93\u5165<strong>\u4fe1\u7528\u5361\u4fe1\u606f<\/strong>\uff0c\u5b8c\u6210\u8d26\u53f7\u6fc0\u6d3b\u3002<\/p>\n\n\n\n<p>\u6fc0\u6d3b\u540e\uff0c\u5c06\u4f1a\u663e\u793aAPI\u7684id\u548ckey\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-db0817bc875748c5a944f98a54749dca_720w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>API\u5b98\u65b9\u6587\u6863\uff1a<a target=\"_blank\" href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/docs.mathpix.com\/%23introduction\" rel=\"noreferrer noopener\">Mathpix API v3 Reference\u200bdocs.mathpix.com<\/a><\/p>\n\n\n\n<p>Github\u4e0a\u7ed9\u51fa\u4e86\u5177\u4f53\u793a\u4f8b\uff1a<a target=\"_blank\" href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/github.com\/Mathpix\/api-examples\" rel=\"noreferrer noopener\">Mathpix\/api-examples\u200bgithub.com<\/a><\/p>\n\n\n\n<p>\u4ee5Python\u4e3a\u4f8b\uff0c\u53ea\u9700\u8981\u5728mathpix.py\u4e2d\u586b\u5199\u81ea\u5df1\u7684id\u548ckey\uff0c\u518d\u8c03\u7528simple.py\u5c31\u80fd\u8fd0\u884c\u3002\u4ece\u793a\u4f8b\u6765\u770b\uff0c\u5b83\u8bc6\u522b\u7684\u662f\u672c\u5730\u56fe\u7247\u3002\u6211\u5728\u5b83\u7684\u57fa\u7840\u4e0a\u52a0\u5165\u4e86\u8bc6\u522b\u526a\u8d34\u677f\u7684\u4ee3\u7801\uff0c\u4ece\u800c\u8fbe\u6210\u4e0eMathpix\u76f8\u4f3c\u5ea6\u4e3a99\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport base64\nimport requests\nimport json\nfrom PIL import ImageGrab\n#\n# Common module for calling Mathpix OCR service from Python.\n#\n# N.B.: Set your credentials in environment variables APP_ID and APP_KEY,\n# either once via setenv or on the command line as in\n# APP_ID=my-id APP_KEY=my-key python3 simple.py \n#\n\nenv = os.environ\n\ndefault_headers = {\n    'app_id': env.get('APP_ID', '\u4f60\u7684id'),\n    'app_key': env.get('APP_KEY', '\u4f60\u7684key'),\n    'Content-type': 'application\/json'\n}\n\nservice = 'https:\/\/api.mathpix.com\/v3\/latex'\n\n#\n# Return the base64 encoding of an image with the given filename.\n#\ndef image_uri(filename):\n    image_data = open(filename, \"rb\").read()\n    return \"data:image\/jpg;base64,\" + base64.b64encode(image_data).decode()\n\n#\n# Call the Mathpix service with the given arguments, headers, and timeout.\n#\ndef latex(args, headers=default_headers, timeout=30):\n    r = requests.post(service,\n        data=json.dumps(args), headers=headers, timeout=timeout)\n    return json.loads(r.text)\n\n\ndef mathpix_clipboard(): # \u8bc6\u522b\u526a\u8d34\u677f\u516c\u5f0f\n    im = ImageGrab.grabclipboard()\n    im.save('equa.png','PNG')\n    r = latex({\n        'src': image_uri(\"equa.png\"),\n        'formats': ['latex_simplified']\n    })\n    print(r['latex_simplified'])\n\nif __name__ == '__main__':\n    mathpix_clipboard()\n    <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\uff0c\u6570\u5b66\u516c\u5f0fOCR\u795e\u5668Mathpix \u5f00\u59cb\u6536\u8d39\uff0c\u4e00\u4e2a\u6708\u53ea\u80fd\u514d\u8d39\u752850\u6b21\uff0c\u518d\u7528\u5c31\u5f975\u5200\u4e00\u6708\uff0c\u5c0f\u4f19\u4f34\u4eec\u987f\u65f6\u53eb\u82e6\u4e0d\u8fed\u3002\u60f3\u60f3\u8fd9\u79cd\u5957\u8def\u56fd\u5185\u4e92\u8054\u7f51\u516c\u53f8\u4e0d\u77e5\u9053\u73a9\u4e86\u591a\u5c11\u6b21\u4e86\uff0c\u4ece\u6ef4\u6ef4\u6253\u8f66\u5230\u7f8e\u56e2\u5916\u5356\u518d\u5230\u5171\u4eab\u5355\u8f66\uff0c\u90fd\u662f\u5148\u57f9\u517b\u6d88\u8d39\u4e60\u60ef\u518d\u6536\u5272\u4e00\u6ce2\u97ed\u83dc\u3002\u4f46\u662f\u5f53\u521d\u5927\u5bb6\u90fd\u53ea\u987e\u4eab\u53d7\u514d\u8d39\u8bc6\u522b\u516c\u5f0f\u5e26\u6765\u7684\u5feb\u611f\uff0c\u54ea\u77e5\u7531\u4fed\u5165\u5962\u6613\uff0c\u7531\u5962\u5165\u4fed\u96be\uff0c\u73b0\u5728\u518d\u624b\u6572\u516c\u5f0f\u771f\u662f\u75db\u82e6\u4e0d\u582a\u3002 \u76ee\u524d\u6765\u770b\uff0c\u7531\u4e8e\u9700\u8981\u8054\u7f51\u8bc6\u522b\uff0c\u57fa\u672c\u6ca1\u6709\u7a7a\u5b50\u53ef\u94bb\u3002\u5f53\u7136\u4e5f\u4e0d\u6392\u9664\u4e2a\u522b\u795e\u4eba\u7528\u5927\u91cf\u90ae\u7bb1\u6765\u767d\u5ad6\uff1a\u5982\u4f55\u770b\u5f85 Mathpix \u6536\u8d39\uff1f\u200bwww.zhihu.com \u4f46\u662f\uff0cMathpix\u5b98\u7f51\u5bf9\u4e8e\u4e00\u4e9b\u6709\u80fd\u529b\u7684\u5f00\u53d1\u8005\u8fd8\u662f\u5f00\u4e86\u4e00\u6247\u540e\u95e8\u7684\uff1aMathpix OCR\u200bmathpix.com \u4ece\u5b83\u63d0\u4f9b\u7684OCR API\u6765\u770b\uff0c\u4e00\u4e2a\u6708\u53ef\u4ee5\u514d\u8d39\u4f7f\u75281000\u6b21\uff01\u5728\u4e4b\u540e\u4e00\u76f4\u523010\u4e07\u6b21\u90fd\u662f0.004\u7f8e\u5143\uff08\u7ea6\u54080.028\u5143\uff09\u4e00\u6b21\u3002\u5bf9\u4e2a\u4eba\u4f7f\u7528\u8005\u800c\u8a00\uff0c1000\u6b21\u5df2\u7ecf\u57fa\u672c\u591f\u4e86\u3002 \u9996\u5148\u9700\u8981\u767b\u5f55\u5e73\u53f0\uff1aMathpixOCR login\u200bdashboard.mathpix.com \u767b\u5f55\u4e4b\u540e\u9700\u8981\u8f93\u5165\u4fe1\u7528\u5361\u4fe1\u606f\uff0c\u5b8c\u6210\u8d26\u53f7\u6fc0\u6d3b\u3002 \u6fc0\u6d3b\u540e\uff0c\u5c06\u4f1a\u663e\u793aAPI\u7684id\u548ckey\uff1a API\u5b98\u65b9\u6587\u6863\uff1aMathpix API v3 Reference\u200bdocs.mathpix.com Github\u4e0a\u7ed9\u51fa\u4e86\u5177\u4f53\u793a\u4f8b\uff1aMathpix\/api-examples\u200bgithub.com \u4ee5Python\u4e3a\u4f8b\uff0c\u53ea\u9700\u8981\u5728mathpix.py\u4e2d\u586b\u5199\u81ea\u5df1\u7684id\u548ckey\uff0c\u518d\u8c03\u7528simple.py\u5c31\u80fd\u8fd0\u884c\u3002\u4ece\u793a\u4f8b\u6765\u770b\uff0c\u5b83\u8bc6\u522b\u7684\u662f\u672c\u5730\u56fe\u7247\u3002\u6211\u5728\u5b83\u7684\u57fa\u7840\u4e0a\u52a0\u5165\u4e86\u8bc6\u522b\u526a\u8d34\u677f\u7684\u4ee3\u7801\uff0c\u4ece\u800c\u8fbe\u6210\u4e0eMathpix\u76f8\u4f3c\u5ea6\u4e3a99<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-27"],"_links":{"self":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":0,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"wp:attachment":[{"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/book.yuekegu.com\/index.php\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}