Kwakwalwarmu ta sadaukar da kanta don sarrafa gani kuma ƙaunarmu ga hotuna ta ta’allaka ne da fahimtarmu da ikon kula da mu. Hotunan suna iya ɗaukar hankalinmu cikin sauƙi kuma na’urori da yawa waɗanda suka haɗa da wayoyin salula na dijital kyamarori, na’urar daukar hotan takardu da sauransu. suna samar da adadi mai yawa na hotuna. Bugu da ari, hotuna suna da algorithms na matsawa daban-daban kuma hotunan raster sun zama ruwan dare a tsakanin su saboda, suna cinye ƙasa da sararin ajiya. Amma duk da haka, tare da nassi na lokaci, mun kawo karshen sama samar da kwafin hotuna, m images da dai sauransu Muna da plethora na aikace-aikace bayar da damar samun kwafin hotuna ciki har da kwafin hoto manemin. Idan kuna da hotuna da aka adana a cikin hotuna na google, kuna iya gwada amfani da google photo duplicate finder, shigar da mai binciken hoto mai kwafi windows 10 ko kwafin hoto mai gano mac (ya danganta da tsarin aiki). Koyaya a cikin wannan labarin, za mu ba da haske kan yadda ake haɓaka mai gano hoto mai ban mamaki ta amfani da REST API wanda za’a iya amfani dashi akan kowane dandamali.
API ɗin sarrafa hoto
Akwai aikace-aikace iri-iri don sarrafa hoto suna ba da fasalulluka don ƙirƙira, shiryawa da sarrafa fayilolin hoto. Har ila yau, suna ba da damar da suka haɗa da binciken hoto dangane da dabarun binciken hoto ko kowane algorithm. Koyaya, idan kuna sha’awar samun tushen tushen tsarin REST API dangane da binciken hoto baya, to Aspose.Imaging Cloud shine tabbataccen zaɓi. Ingin bincikensa mai ƙarfi yana taimaka wa masu haɓakawa don ƙara fasalin binciken hoto na baya a cikin aikace-aikacen su akan kowane dandamali ba tare da matsala ba. Hakanan kuna iya fara aikin kwatanta hoto don nemo kwafin hoto a tsakanin wasu hotuna da yawa. Sakamakon wannan aikin, kuna samun jerin mafi yawan hotuna masu kama da juna bisa ga sharuɗɗa masu zuwa:
- Matsayin kamanni
- Madaidaicin madaidaicin madaidaicin
- Algorithm na kwatanta
Yanzu don samun makamancin sarrafa hoto da ikon gano hoto na kwafi a cikin aikace-aikacen Java, muna buƙatar amfani da Aspose.Imaging Cloud SDK for Java kamar yadda yake a kusa da Cloud API. Don haka mataki na gaba shine ƙara bayaninsa a cikin aikin java ta haɗa da bin bayanai a cikin pom.xml na maven build type project.
<repositories>
<repository>
<id>aspose-cloud</id>
<name>artifact.aspose-cloud-releases</name>
<url>http://artifact.aspose.cloud/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging-cloud</artifactId>
<version>22.4</version>
</dependency>
</dependencies>
Yanzu idan baku ƙirƙiri asusu akan [Aspose Cloud Dashboard] ba 4, zaku iya yin rajista don Gwajin Kyauta ta hanyar ingantaccen adireshin imel. Yanzu shiga ta amfani da sabon asusun da aka ƙirƙira kuma bincika/ƙirƙiri ID na abokin ciniki da Sirrin Abokin ciniki a Cloud Dashboard. Ana buƙatar waɗannan cikakkun bayanai don dalilai na tantancewa a cikin sassan masu zuwa.
Nemo Kwafin Hoto ta amfani da Java
Binciken Hoto baya dabara ce da ke taimaka muku bincika hotuna masu kama da gani dangane da hoton samfurin ku. An ba da ƙasa a cikin mafi yawan lokuta amfani don wannan fasalin:
Nemo kwafin hoto kuma cire kwafin Bincika hotuna masu kama da abun ciki Bincika abubuwan da basu dace ba Nemo hotuna da aka sanya hannu a dijital
API ɗin mu a halin yanzu yana goyan bayan binciken tushen abun ciki, binciken hoto kwafi, binciken hoto ta alamun rajista na al’ada, kwatancen hoto da gano kamanni da ayyukan haɓakar fasalin Hoto. Yanzu a cikin wannan sashe, za mu tattauna cikakkun bayanai kan yadda ake nemo kwafin hotuna ta amfani da dabarar hoton baya. Yanzu don cika wannan buƙatun, muna amfani da AKAZE algorithm don gano fasali da RandomBinaryTree algorithm don daidaita fasalin a cikin misali. Za mu bi waɗannan matakan don nemo kwafin hotuna:
- Loda Hotuna zuwa Ma’ajiyar Gajimare
- Ƙirƙiri Maganar Bincike
- Cire Halayen Hoto
- Nemo Kwafin Hotuna
Loda Hotuna zuwa Ma’ajiyar Gajimare
Da fatan za a yi amfani da snippet na lamba mai zuwa don loda fayilolin hoto daga faifan gida zuwa ma’ajiyar gajimare
- Da farko, ƙirƙiri wani abu na ImagingApi yayin samar da ClientID da Client
- Abu na biyu, karanta duk fayilolin hoto daga ƙayyadaddun shugabanci
- Tace fayilolin hoto kawai kuma ƙara su zuwa lissafin da aka tace
- Loda hotuna zuwa ma’ajiyar gajimare ta amfani da hanyar uploadFile(…) yayin ɗaukar abun UploadFileRequest azaman hujja
// Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
String clientId = "7ef10407-c1b7-43bd-9603-5ea9c6db83cd";
String clientSecret = "ba7cc4dc0c0478d7b508dd8ffa029845";
// haifar da Hoto abu
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);
File directory = new File("/Users/");
//Samo duk fayiloli daga babban fayil
File[] allFiles = directory.listFiles();
if (allFiles == null || allFiles.length == 0) {
throw new RuntimeException("No files present in the directory: " + directory.getAbsolutePath());
}
//Saita karin hoton da ake buƙata anan.
List<String> supportedImageExtensions = Arrays.asList("jpg", "png", "gif", "webp");
int counter =0;
//Tace fayilolin hoto kawai
List<File> acceptedImages = new ArrayList<>();
for (File file : allFiles) {
//Fassara tsawo na fayil
String fileExtension = file.getName().substring(file.getName().lastIndexOf(".") + 1);
//Bincika idan an jera tsawo a cikin Hotunan da ake tallafawa
if (supportedImageExtensions.stream().anyMatch(fileExtension::equalsIgnoreCase)) {
//Ƙara hoton zuwa jerin abubuwan da aka tace
acceptedImages.add(file);
// load farko gabatarwar PowerPoint
byte[] bytes = Files.readAllBytes(file.toPath());
// ƙirƙirar buƙatar loda fayil
UploadFileRequest request = new UploadFileRequest(acceptedImages.get(counter).getName(),bytes,null);
// loda fayil ɗin hoto zuwa ma'ajiyar gajimare
imageApi.uploadFile(request);
// ƙara lissafin fayil
counter+=1;
}
}
Ƙirƙiri Maganar Bincike
- Da farko muna buƙatar saka fasalin gano algorithm a matsayin akaze
- Na biyu, saka algorithm don daidaita fasalin azaman randomBinaryTree
- Na uku, ƙirƙiri Buƙatar Neman Hoto ta amfani da CreateImageSearchRequest abu
- Yanzu ƙirƙiri matsayin mahallin bincike ta hanyar ƙirƙirarImageSearch(…) hanya
// ƙayyade algorithm don gano fasali
String detector = "akaze";
// ƙayyade algorithm don daidaita fasalin
String matchingAlgorithm = "randomBinaryTree";
String folder = null; // File will be saved at the root of the storage
String storage = null; // We are using default Cloud Storage
// Ƙirƙiri Buƙatun Neman Hoto
CreateImageSearchRequest createSearchContextRequest = new CreateImageSearchRequest(detector,matchingAlgorithm, folder, storage);
// ƙirƙirar yanayin mahallin bincike
SearchContextStatus status = imageApi.createImageSearch(createSearchContextRequest);
// sami Matsayin ID na bincike Yanar gizo
String searchContextId = status.getId();
Cire Halayen Hoto
Yanzu lokaci ya yi don cire fasalolin hotuna da ƙara su zuwa mahallin bincike.
// Cire fasalulluka hotuna kuma ƙara su zuwa mahallin bincike
for (File file : allFiles)
{
CreateImageFeaturesRequest request = new CreateImageFeaturesRequest(searchContextId, null, null, "internal", null,null);
imageApi.createImageFeatures(request);
}
Nemo Kwafin Hotuna
- Ƙayyade ƙimar maƙalar kamanni
- Abu na biyu, ƙirƙirar saitin hoto mai kwafi ta amfani da abun ImageDuplicatesSet
- Yanzu sake maimaita ta cikin jerin kwafin hotuna kuma nemo kamannin hoto ta amfani da hanyar samun kamanni(…).
// Ƙayyade ƙimar maƙasudin kamanni
Double similarityThreshold = 90.0;
// ƙirƙirar saitin hoto kwafi
ImageDuplicatesSet result = imageApi.findImageDuplicates(
new FindImageDuplicatesRequest(status.getId(), similarityThreshold, folder, storage));
// buga kwafin hotuna
System.out.println("Duplicates Set Count: " + result.getDuplicates().size());
for (ImageDuplicates duplicates : result.getDuplicates())
{
System.out.println("Duplicates:");
for (SearchResult duplicate : duplicates.getDuplicateImages())
{
System.out.println("ImageName: " + duplicate.getImageId() +
", Similarity: " + duplicate.getSimilarity());
}
}
Nemo Kwafin Hoto ta amfani da Umarnin CURL
A cikin wannan sashe, za mu yi amfani da damar yin amfani da umarnin cURL don samun damar APIs REST akan tashar layin umarni. Yanzu a matsayin buƙatun farko, muna buƙatar fara samar da alamar samun damar JWT (bisa ga shaidar abokin ciniki) yayin aiwatar da umarni mai zuwa.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Wannan matakin yana tsammanin cewa ana loda duk hotuna zuwa ma’ajiyar girgije kuma yanzu muna buƙatar ƙirƙirar ID na mahallin bincike ta hanyar CreateImageSearch API kiran. Da fatan za a aiwatar da umarni mai zuwa
curl -v -X POST "https://api.aspose.cloud/v3.0/imaging/ai/imageSearch/create?detector=akaze&matchingAlgorithm=randomBinaryTree" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Jikin amsa
{
"id": "0b9ac539-07fb-462a-91cb-8a8d5069ba4d",
"searchStatus": "Idle"
}
Da fatan za a aiwatar da umarni mai zuwa don nemo kwafin Hoto ta amfani da FindImageDuplicates API call. A cikin umarni mai zuwa, ana amfani da ID ɗin mahallin binciken da aka samar a sama.
curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/ai/imageSearch/da150333-57b4-4371-b13d-4889578ce2bd/findDuplicates?similarityThreshold=90" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Kammalawa
A cikin wannan labarin, mun koyi game da cikakkun bayanai kan yadda ake samun Hotunan Kwafi ta amfani da Java Cloud SDK. Hakazalika, mun koyi yadda umarnin cURL zai iya zama mai neman hoto mai kwafi. Idan kuna buƙatar gwada waɗannan APIs a cikin mai bincike, da fatan za a gwada amfani da swagger API Reference. Hakazalika, muna ba da shawarar sosai bincika Takardun Samfura don koyan wasu abubuwan ban sha’awa da wannan API ke bayarwa. Hakanan, da fatan za a lura cewa ana buga duk SDK ɗin mu a ƙarƙashin lasisin MIT, don haka kuna iya yin la’akari da zazzage cikakkiyar lambar tushe daga GitHub kuma gyara ta gwargwadon buƙatun ku. A cikin kowane matsala, kuna iya la’akari da kusantar mu don ƙuduri mai sauri ta hanyar [Tallafin tallafin samfur 9.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: