Search in sources :

Example 6 with DetectFacesOptions

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionIT method testDetectFacesFromBytes.

/**
 * Test detect faces from bytes or stream.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testDetectFacesFromBytes() throws IOException {
    File images = new File(IMAGE_FACE_FILE);
    DetectFacesOptions options = new DetectFacesOptions.Builder().imagesFile(images).build();
    DetectedFaces result = service.detectFaces(options).execute();
    assertDetectedFaces(result, options);
}
Also used : DetectFacesOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions) DetectedFaces(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces) File(java.io.File) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 7 with DetectFacesOptions

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testDetectFaces.

/**
 * Test detect faces.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testDetectFaces() throws IOException, InterruptedException {
    DetectedFaces mockResponse = loadFixture(FIXTURE_FACES, DetectedFaces.class);
    server.enqueue(new MockResponse().setBody(mockResponse.toString()));
    // execute request
    File images = new File(IMAGE_FILE);
    DetectFacesOptions options = new DetectFacesOptions.Builder().imagesFile(images).build();
    DetectedFaces serviceResponse = service.detectFaces(options).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = PATH_DETECT_FACES + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY;
    assertEquals(path, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(serviceResponse, mockResponse);
    String contentDisposition = "Content-Disposition: form-data; name=\"images_file\"; filename=\"test.zip\"";
    String body = request.getBody().readUtf8();
    assertTrue(body.contains(contentDisposition));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DetectFacesOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions) DetectedFaces(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces) File(java.io.File) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

DetectedFaces (com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces)7 DetectFacesOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectFacesOptions)6 Test (org.junit.Test)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 File (java.io.File)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 VisualRecognition (com.ibm.watson.developer_cloud.visual_recognition.v3.VisualRecognition)1 Face (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Face)1 ImageWithFaces (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ImageWithFaces)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Document (org.jbpm.document.Document)1 FaceDetectionResult (org.jbpm.process.workitem.ibm.watson.result.FaceDetectionResult)1