किसी इमेज पर Optical Character Recognition (OCR) करना एक जटिल काम है। यह विषय चरण-दर-चरण बताता है कि सी # में छवि से पाठ को जल्दी और आसानी से कैसे निकाला जाए। Aspose.OCR for .NET का उपयोग करके आप कुछ ही चरणों में छवि से C# में वर्णों को आसानी से पढ़ सकते हैं।
सी#में छवि से पाठ निकालने के लिए कदम
- Aspose.OCR for .NET NuGet पैकेज का प्रयोग करें
- पहले Aspose.OCR namespace संदर्भ शामिल करें
- Aspose लाइसेंस लागू करने के लिए SetLicense विधि का उपयोग करें
- AsposeOcr Class इंस्टेंस का ऑब्जेक्ट बनाएं
- OCR लागू करके इमेज से टेक्स्ट निकालने के लिए RecognizeImage विधि का उपयोग करें
- फ़ाइलस्ट्रीम और स्ट्रीमवाइटर कक्षाओं का उपयोग करके निकाले गए टेक्स्ट को टेक्स्ट फ़ाइल में सहेजें
ऊपर दिए गए चरण आपको दिखाते हैं कि सी # में छवि से वर्ण पढ़ना बहुत आसान है। उपरोक्त चरणों के लिए कोड नीचे दिया गया है।
सी # में छवि से पाठ निकालने के लिए कोड
using System; | |
using System.IO; | |
//Add Aspose.OCR for .NET package reference | |
//Use following namespaces to Extract Text from Image | |
using Aspose.OCR; | |
namespace ExtractTextFromImage | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set Aspose license before extracting text from image | |
//using Aspose.OCR for .NET | |
Aspose.OCR.License AsposeOCRLicense = new Aspose.OCR.License(); | |
AsposeOCRLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//Create an instance of AsposeOcr class before you can apply | |
//OCR on an image to extract the text from it | |
AsposeOcr ExtractTextFromImage = new AsposeOcr(); | |
//Read image using RecognizeImage method on which OCR need to be applied for text extraction | |
string TextExtractedFromImage = ExtractTextFromImage.RecognizeImage("ExampleOCRImageToExtractText.jpg"); | |
//Save extracted text to a text file using File Stream and StreamWriter | |
//classes of System.IO | |
FileStream FStream = new FileStream("ExtractTextFromImageUsingOCR.txt", FileMode.Create); | |
StreamWriter SWriter = new StreamWriter(FStream); | |
//Write extracted text to the file | |
SWriter.WriteLine(TextExtractedFromImage); | |
SWriter.Flush(); | |
//Close FileStream and StreamWriter bojects | |
SWriter.Close(); | |
FStream.Close(); | |
} | |
} | |
} |
यदि आप C# भाषा का उपयोग कर रहे हैं तो किसी भी प्रकार के .NET एप्लिकेशन के लिए दृष्टिकोण समान है। आप छवि से सभी पाठ निकालना चाहते हैं, या किसी छवि से पंक्ति दर पंक्ति पाठ पढ़ना चाहते हैं, .NET के लिए Aspose.OCR ऐसा करने में आपकी सहायता कर सकता है।