Skip to content

Commit

Permalink
Merged develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Sekachev committed Aug 6, 2021
2 parents df53299 + e1198c3 commit 788eea5
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 80 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- TDB
- Fixed multiple tasks moving (<https://github.com/openvinotoolkit/cvat/pull/3517>)
- Fixed task creating CLI parameter (<https://github.com/openvinotoolkit/cvat/pull/3519>)

### Security

Expand Down
4 changes: 2 additions & 2 deletions components/analytics/logstash/logstash.conf
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ output {
if [type] == "client" {
elasticsearch {
hosts => ["${LOGSTASH_OUTPUT_HOST}"]
index => "cvat.client"
index => "%{[@metadata][target_index_client]}"
user => "${LOGSTASH_OUTPUT_USER:}"
password => "${LOGSTASH_OUTPUT_PASS:}"
manage_template => false
}
} else if [type] == "server" {
elasticsearch {
hosts => ["${LOGSTASH_OUTPUT_HOST}"]
index => "cvat.server"
index => "%{[@metadata][target_index_server]}"
user => "${LOGSTASH_OUTPUT_USER:}"
password => "${LOGSTASH_OUTPUT_PASS:}"
manage_template => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface DispatchToProps {
updateAnnotations(statesToUpdate: any[]): void;
createAnnotations(sessionInstance: any, frame: number, statesToCreate: any[]): void;
fetchAnnotations(): void;
changeFrame(toFrame: number, fillBuffer?: boolean, frameStep?: number, forceUpdate?: boolean):void;
changeFrame(toFrame: number, fillBuffer?: boolean, frameStep?: number, forceUpdate?: boolean): void;
}

interface State {
Expand All @@ -66,8 +66,8 @@ interface State {
}

interface ImageModifier {
modifier: ImageProcessing,
alias: string
modifier: ImageProcessing;
alias: string;
}

const core = getCore();
Expand Down Expand Up @@ -229,21 +229,22 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
notification.error({
description: error.toString(),
message: 'OpenCV.js processing error occured',
className: 'cvat-notification-notice-opencv-processing-error',
});
}
};

private runImageModifier = async ():Promise<void> => {
private runImageModifier = async (): Promise<void> => {
const { activeImageModifiers } = this.state;
const {
frameData, states, curZOrder, canvasInstance, frame,
} = this.props;
try {
if (activeImageModifiers.length !== 0 && activeImageModifiers[0].modifier.currentProcessedImage !== frame) {
this.enableCanvasForceUpdate();
const canvas: HTMLCanvasElement | undefined = window.document.getElementById('cvat_canvas_background') as
| HTMLCanvasElement
| undefined;
const canvas: HTMLCanvasElement | undefined = window.document.getElementById(
'cvat_canvas_background',
) as HTMLCanvasElement | undefined;
if (!canvas) {
throw new Error('Element #cvat_canvas_background was not found');
}
Expand All @@ -253,8 +254,11 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
throw new Error('Canvas context is empty');
}
const imageData = context.getImageData(0, 0, width, height);
const newImageData = activeImageModifiers.reduce((oldImageData, activeImageModifier) =>
activeImageModifier.modifier.processImage(oldImageData, frame), imageData);
const newImageData = activeImageModifiers.reduce(
(oldImageData, activeImageModifier) =>
activeImageModifier.modifier.processImage(oldImageData, frame),
imageData,
);
const imageBitmap = await createImageBitmap(newImageData);
frameData.imageData = imageBitmap;
canvasInstance.setup(frameData, states, curZOrder);
Expand All @@ -263,6 +267,7 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
notification.error({
description: error.toString(),
message: 'OpenCV.js processing error occured',
className: 'cvat-notification-notice-opencv-processing-error',
});
} finally {
this.disableCanvasForceUpdate();
Expand Down Expand Up @@ -298,12 +303,12 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
return points;
}

private imageModifier(alias: string): ImageProcessing|null {
private imageModifier(alias: string): ImageProcessing | null {
const { activeImageModifiers } = this.state;
return activeImageModifiers.find((imageModifier) => imageModifier.alias === alias)?.modifier || null;
}

private disableImageModifier(alias: string):void {
private disableImageModifier(alias: string): void {
const { activeImageModifiers } = this.state;
const index = activeImageModifiers.findIndex((imageModifier) => imageModifier.alias === alias);
if (index !== -1) {
Expand All @@ -314,22 +319,25 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
}
}

private enableImageModifier(modifier: ImageProcessing, alias: string): void{
this.setState((prev: State) => ({
...prev,
activeImageModifiers: [...prev.activeImageModifiers, { modifier, alias }],
}), () => {
this.runImageModifier();
});
private enableImageModifier(modifier: ImageProcessing, alias: string): void {
this.setState(
(prev: State) => ({
...prev,
activeImageModifiers: [...prev.activeImageModifiers, { modifier, alias }],
}),
() => {
this.runImageModifier();
},
);
}

private enableCanvasForceUpdate():void{
private enableCanvasForceUpdate(): void {
const { canvasInstance } = this.props;
canvasInstance.configure({ forceFrameUpdate: true });
this.canvasForceUpdateWasEnabled = true;
}

private disableCanvasForceUpdate():void{
private disableCanvasForceUpdate(): void {
if (this.canvasForceUpdateWasEnabled) {
const { canvasInstance } = this.props;
canvasInstance.configure({ forceFrameUpdate: false });
Expand Down Expand Up @@ -376,7 +384,7 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
);
}

private renderImageContent():JSX.Element {
private renderImageContent(): JSX.Element {
return (
<Row justify='start'>
<Col>
Expand Down
4 changes: 2 additions & 2 deletions cvat-ui/src/components/move-task-modal/move-task-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ export default function MoveTaskModal(): JSX.Element {
const [labelMap, setLabelMap] = useState<{ [key: string]: LabelMapperItemValue }>({});

const initValues = (): void => {
const labelValues: { [key: string]: LabelMapperItemValue } = {};
if (task) {
const labelValues: { [key: string]: LabelMapperItemValue } = {};
task.labels.forEach((label: any) => {
labelValues[label.id] = {
labelId: label.id,
newLabelName: null,
clearAttributes: true,
};
});
setLabelMap(labelValues);
}
setLabelMap(labelValues);
};

const onCancel = (): void => {
Expand Down
34 changes: 18 additions & 16 deletions cvat-ui/src/utils/opencv-wrapper/histogram-equalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@

import { ImageProcessing } from './opencv-interfaces';

export interface HistogramEqualization extends ImageProcessing{
processImage: (src:ImageData, frameNumber: number)=>ImageData;
export interface HistogramEqualization extends ImageProcessing {
processImage: (src: ImageData, frameNumber: number) => ImageData;
}

interface HashedImage{
frameNumber: number,
frameData: ImageData,
timestamp: number,
interface HashedImage {
frameNumber: number;
frameData: ImageData;
timestamp: number;
}

export default class HistogramEqualizationImplementation implements HistogramEqualization {
private readonly bufferSize: number = 20;
private cv:any;
private cv: any;
private histHash: HashedImage[];
public currentProcessedImage: number | undefined;

constructor(cv:any) {
constructor(cv: any) {
this.cv = cv;
this.histHash = [];
}

public processImage(src:ImageData, frameNumber: number) : ImageData {
public processImage(src: ImageData, frameNumber: number): ImageData {
const hashedFrame = this.hashedFrame(frameNumber);
if (!hashedFrame) {
const { cv } = this;
Expand All @@ -49,9 +49,12 @@ export default class HistogramEqualizationImplementation implements HistogramEqu
cv.equalizeHist(Y, equalizedY);
Y.delete();
channels = new cv.MatVector();
channels.push_back(equalizedY); equalizedY.delete();
channels.push_back(U); U.delete();
channels.push_back(V); V.delete();
channels.push_back(equalizedY);
equalizedY.delete();
channels.push_back(U);
U.delete();
channels.push_back(V);
V.delete();
cv.merge(channels, YUVDist);
cv.cvtColor(YUVDist, RGBDist, cv.COLOR_YUV2RGB, 0);
cv.cvtColor(RGBDist, RGBADist, cv.COLOR_RGB2RGBA, 0);
Expand All @@ -60,8 +63,7 @@ export default class HistogramEqualizationImplementation implements HistogramEqu
this.hashFrame(imgData, frameNumber);
return imgData;
} catch (e) {
console.log('Histogram equalization error', e);
return src;
throw new Error(e.toString());
} finally {
if (matImage) matImage.delete();
if (channels) channels.delete();
Expand All @@ -77,15 +79,15 @@ export default class HistogramEqualizationImplementation implements HistogramEqu
}
}

private hashedFrame(frameNumber: number): ImageData|null {
private hashedFrame(frameNumber: number): ImageData | null {
const hashed = this.histHash.find((_hashed) => _hashed.frameNumber === frameNumber);
if (hashed) {
hashed.timestamp = Date.now();
}
return hashed?.frameData || null;
}

private hashFrame(frameData:ImageData, frameNumber:number):void{
private hashFrame(frameData: ImageData, frameNumber: number): void {
if (this.histHash.length >= this.bufferSize) {
const leastRecentlyUsed = this.histHash[0];
const currentTimestamp = Date.now();
Expand Down
10 changes: 4 additions & 6 deletions cvat-ui/src/utils/opencv-wrapper/opencv-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Contours {
}

export interface ImgProc {
hist: () => HistogramEqualization
hist: () => HistogramEqualization;
}

export class OpenCVWrapper {
Expand All @@ -41,10 +41,6 @@ export class OpenCVWrapper {
const contentLength = response.headers.get('Content-Length');
const { body } = response;

if (contentLength === null) {
throw new Error('Content length is null, but necessary');
}

if (body === null) {
throw new Error('Response body is null, but necessary');
}
Expand All @@ -64,7 +60,9 @@ export class OpenCVWrapper {
if (value instanceof Uint8Array) {
decodedScript += decoder.decode(value);
receivedLength += value.length;
const percentage = (receivedLength * 100) / +(contentLength as string);
// Cypress workaround: content-length is always zero in cypress, it is done optional here
// Just progress bar will be disabled
const percentage = contentLength ? (receivedLength * 100) / +(contentLength as string) : 0;
onProgress(+percentage.toFixed(0));
}
}
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/manual/advanced/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ comprehensive CVAT administration tool in the future.

Overview of functionality:

- Create a new task (supports name, bug tracker, labels JSON, local/share/remote files)
- Create a new task (supports name, bug tracker, project, labels JSON, local/share/remote files)
- Delete tasks (supports deleting a list of task IDs)
- List all tasks (supports basic CSV or JSON output)
- Download JPEG frames (supports a list of frame IDs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// <reference types="cypress" />

import { taskName } from '../../support/const';
import { generateString } from '../../support/utils';

context('Settings. Default number of points in polygon approximation.', () => {
const caseId = '100';
Expand All @@ -21,17 +22,11 @@ context('Settings. Default number of points in polygon approximation.', () => {

function testCheckSliderAttrValuenow(expectedValue) {
testOpenSettingsWorkspace();
cy.get('.cvat-workspace-settings-approx-poly-threshold').find('[role="slider"]').then((slider) => {
expect(slider.attr('aria-valuenow')).to.be.equal(expectedValue);
});
}

function generateString(countPointsToMove) {
let action = '';
for (let i = 0; i < countPointsToMove; i++) {
action += '{rightarrow}';
}
return action;
cy.get('.cvat-workspace-settings-approx-poly-threshold')
.find('[role="slider"]')
.then((slider) => {
expect(slider.attr('aria-valuenow')).to.be.equal(expectedValue);
});
}

before(() => {
Expand All @@ -43,7 +38,7 @@ context('Settings. Default number of points in polygon approximation.', () => {
testOpenSettingsWorkspace();
cy.get('.cvat-workspace-settings-approx-poly-threshold')
.find('[role="slider"]')
.type(generateString(4))
.type(generateString(4, 'rightarrow'))
.then((slider) => {
const sliderAttrValueNow = slider.attr('aria-valuenow');
const sliderAttrValuemin = slider.attr('aria-valuemin');
Expand Down
Loading

0 comments on commit 788eea5

Please sign in to comment.