void OcropusThread::segmentImage(QImage* image, const QString imagepath, const QString segtype)
{
    qDebug() << "Processing image in " << this->thread()->currentThreadId();

    try {
        colib::bytearray page_binary;
        iulib::read_image_binary(page_binary, imagepath.toStdString().c_str());

        emit workerStatus(QString("Loading page segmentation component..."));
        colib::intarray page_seg;
        autodel<ocropus::ISegmentPage> segmenter;
        ocropus::make_component(segtype.toStdString().c_str(), segmenter);

        emit workerStatus(QString("Running segmentation..."));
        segmenter->segment(page_seg,page_binary);
        int height = page_seg.dim(1) - 1;
        for (int x = 0; x < page_seg.dim(0); x++) {
            for (int y = 0; y < page_seg.dim(1); y++) {
                image->setPixel(x, height - y, page_seg.at(x, y));
            }
        }      

        emit doneImage();

        extractLineRects(page_seg, image);
        extractParagraphRects(page_seg, image);

        emit workerStatus(QString("Segmentation done"));

    } catch(const char* ex) {
        qDebug() << "Threw exception: " << ex;
    }
}
Пример #2
0
void runWorkerPing(){
	struct workerNode *ptr = head;

	int i = 0;

	while(ptr != NULL){

		// Get IP and Port and Ping the worker
		//Convert ip to string
		char address[50];
		sprintf(address, "%d.%d.%d.%d", ptr->ip[0], ptr->ip[1], ptr->ip[2], ptr->ip[3]);

		printf("Worker  %d : ip = %s : port = %d\n",i,address,ptr->port);

		if(workerStatus(address, ptr->port) < 0) {
			// Deregister the worker
			scanListWorkerDR(ptr->ip, ptr->port);

			puts("Removing");
		}else{
			puts("Keeping");
		}

		ptr = ptr->next;
		i++;
	}

}
void OcropusThread::extractParagraphRects(colib::intarray& in, QImage* image)
{
    emit workerStatus(QString("Extracting paragraphs..."));
    ocropus::RegionExtractor regionextractor;
    regionextractor.setPageParagraphs(in);
    drawRectArray(regionextractor.boxes, image, QColor(0, 0, 255));    
    emit doneImage();
}
void OcropusThread::extractLineRects(colib::intarray& in, QImage* image)
{
    emit workerStatus(QString("Extracting lines..."));
    ocropus::RegionExtractor regionextractor;
    regionextractor.setPageLines(in);
    drawRectArray(regionextractor.boxes, image, QColor(255, 0, 0));
    emit doneImage();
}
void OcropusThread::run()
{
    // start an event loop
    qDebug() << "Starting thread " << this->thread()->currentThreadId();

    emit workerStatus(QString("Initialising Ocropus component system..."));
    ocropus::init_ocropus_components();

    exec();
}
Пример #6
0
int sendAllWorkersToServer(int sock){
	// Scan through the link list and send send one worker at a time
	struct workerNode *ptr = head;

	if(ptr == NULL){
		if(sendInt(sock, 0) < 0){
			puts("Sending no worker present status failed");
			return -1;
		}else{
			puts("No Worker Found In List");
			return 1;
		}
	}

	while(ptr != NULL){
		// Send worker IP, Convert IP to string
		char address[50];
		sprintf(address, "%d.%d.%d.%d", ptr->ip[0], ptr->ip[1], ptr->ip[2], ptr->ip[3]);

		// Worker found, make sure it is still alive by pinging it
		if(workerStatus(address, ptr->port) < 0){
			// Worker not present, de-register it and look for another one
			scanListWorkerDR(ptr->ip, ptr->port);
		}else{
			if(sendWorkerDetails(sock, ptr) < 0){
				puts("Failed to send worker details");
				return -1;
			}
		}

		// Next Worker
		ptr = ptr->next;
	}

	// Inform the server, there are no more workers
	if(sendInt(sock, 0) < 0){
		puts("Sending no worker present status failed");
		return -1;
	}

	return 1;
}
Пример #7
0
int runWorkerLookup(int sock){
	//Look for the worker with least load
	//Find the worker and send the IP and Port to the tiny google server
	struct workerNode *ptr = lockerForWorkerLookup();

	if(ptr == NULL){
		//Send Worker not Found
		if(sendInt(sock, 0) < 0){
			puts("Send Query result Failed");
			return -1;
		}

		puts("No Worker Found");
		return -1;
	}else{
		//Convert ip to string
		char address[50];
		sprintf(address, "%d.%d.%d.%d", ptr->ip[0], ptr->ip[1], ptr->ip[2], ptr->ip[3]);

		// Worker found, make sure it is still alive by pinging it
		if(workerStatus(address, ptr->port) < 0){
			// Worker not present, deregister it and look for another one
			locker(1, ptr->ip, ptr->port, 0);
			runWorkerLookup(sock);
		}

		if(sendWorkerDetails(sock, ptr) < 0){
			puts("Failed to send worker details");
			return -1;
		}
	}

	//Successful
	puts("Server got Worker");
	return 1;
}