我遵循了《 AWS Rekognition开发人员指南》,并使用Java中的CreateStreamProcessor编写了一个流处理器。
import com.amazonaws.services.rekognition.AmazonRekognition;
import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
import com.amazonaws.services.rekognition.model.*;
public class StreamProcessor {
private String streamProcessorName;
private String kinesisVideoStreamArn;
private String kinesisDataStreamArn;
private String roleArn;
private String collectionId;
private float matchThreshold;
private AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
public void createStreamProcessor() {
KinesisVideoStream kinesisVideoStream = new KinesisVideoStream().withArn(kinesisVideoStreamArn);
StreamProcessorInput streamProcessorInput = new StreamProcessorInput().withKinesisVideoStream(kinesisVideoStream);
KinesisDataStream kinesisDataStream = new KinesisDataStream().withArn(kinesisDataStreamArn);
StreamProcessorOutput streamProcessorOutput = new StreamProcessorOutput().withKinesisDataStream(kinesisDataStream);
FaceSearchSettings faceSearchSettings = new FaceSearchSettings().withCollectionId(collectionId)
.withFaceMatchThreshold(matchThreshold);
StreamProcessorSettings streamProcessorSettings = new StreamProcessorSettings().withFaceSearch(faceSearchSettings);
CreateStreamProcessorResult createStreamProcessorResult = rekognitionClient.createStreamProcessor(
new CreateStreamProcessorRequest().withInput(streamProcessorInput).withOutput(streamProcessorOutput)
.withSettings(streamProcessorSettings).withRoleArn(roleArn).withName(streamProcessorName));
System.out.println("StreamProcessorArn - " +
createStreamProcessorResult.getStreamProcessorArn());
}
public void startStreamProcessor() {
StartStreamProcessorResult startStreamProcessorResult = rekognitionClient.startStreamProcessor(
new StartStreamProcessorRequest().withName(streamProcessorName));
}
public void stopStreamProcessorSample() {
StopStreamProcessorResult stopStreamProcessorResult = rekognitionClient.stopStreamProcessor(
new StopStreamProcessorRequest().withName(streamProcessorName));
}
public void deleteStreamProcessorSample() {
DeleteStreamProcessorResult deleteStreamProcessorResult = rekognitionClient.deleteStreamProcessor(
new DeleteStreamProcessorRequest().withName(streamProcessorName));
}
public void describeStreamProcessorSample() {
DescribeStreamProcessorResult describeStreamProcessorResult = rekognitionClient.describeStreamProcessor(
new DescribeStreamProcessorRequest().withName(streamProcessorName));
System.out.println("Arn - " + describeStreamProcessorResult.getStreamProcessorArn());
System.out.println("Input kinesisVideo stream - " + describeStreamProcessorResult.getInput()
.getKinesisVideoStream().getArn());
System.out.println("Output kinesisData stream - " + describeStreamProcessorResult.getOutput()
.getKinesisDataStream().getArn());
System.out.println("RoleArn - " + describeStreamProcessorResult.getRoleArn());
System.out.println("CollectionId - " + describeStreamProcessorResult.getSettings().getFaceSearch()
.getCollectionId());
System.out.println("Status - " + describeStreamProcessorResult.getStatus());
System.out.println("Status message - " + describeStreamProcessorResult.getStatusMessage());
System.out.println("Creation timestamp - " + describeStreamProcessorResult.getCreationTimestamp());
System.out.println("Last updatClient rekognitionClient = new AmazonRekognitionClient()e timestamp - "
+ describeStreamProcessorResult.getLastUpdateTimestamp());
}
public void listStreamProcessorSample() {
ListStreamProcessorsResult listStreamProcessorsResult = rekognitionClient.listStreamProcessors(
new ListStreamProcessorsRequest().withMaxResults(100));
for (com.amazonaws.services.rekognition.model.StreamProcessor streamProcessor :
listStreamProcessorsResult.getStreamProcessors()) {
System.out.println("StreamProcessor name - " + streamProcessor.getName());
System.out.println("Status - " + streamProcessor.getStatus());
}
}
}
但是我不知道如何启动流处理器?我是否只需编写main方法并调用createStreamProcessor()
函数?还是我需要做其他事情:就像指南中提到的StartStreamProcessor
一样?
答案 0 :(得分:1)
是的,您必须使用以下API启动流预处理器: https://docs.aws.amazon.com/rekognition/latest/dg/API_StartStreamProcessor.html
rekognitionClient.startStreamProcessor(name= "my-stream-1")